# Buggy code
def load_messages(themes, translations, default_lang):
    """Load theme's messages into context.

    All the messages from parent themes are loaded,
    and "younger" themes have priority.
    """
    messages = Functionary(dict, default_lang)
    oldpath = sys.path[:]
    for theme_name in themes[::-1]:
        msg_folder = os.path.join(get_theme_path(theme_name), "messages")
        default_folder = os.path.join(get_theme_path("base"), "messages")
        sys.path.insert(0, default_folder)
        sys.path.insert(0, msg_folder)
        english = __import__("messages_en")
        for lang in list(translations.keys()):
            try:
                translation = __import__("messages_" + lang)
                # If we don't do the reload, the module is cached
                reload(translation)
                if (
                    sorted(translation.MESSAGES.keys())
                    != sorted(english.MESSAGES.keys())
                    and lang not in warned
                ):
                    warned.append(lang)
                    LOGGER.warn(
                        "Incomplete translation for language '{0}'.".format(lang)
                    )
                messages[lang].update(english.MESSAGES)
                messages[lang].update(translation.MESSAGES)
                del translation
            except ImportError as orig:
                raise LanguageNotFoundError(lang, orig)
    sys.path = oldpath
    return messages


# Traceback (TypeError)
TaskError - taskid:render_indexes:output/tr/es/weblog/index-117.html
PythonAction Error
Traceback (most recent call last):
File "/home/ralsina/.virtualenvs/nikola/local/lib/python2.7/site-packages/doit/action.py", line 360, in execute
returned_value = self.py_callable(*self.args, **kwargs)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/nikola.py", line 751, in render_template
template_name, None, local_context)
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/plugins/template/mako.py", line 108, in render_template
data = template.render_unicode(**context)
File "/home/ralsina/.virtualenvs/nikola/local/lib/python2.7/site-packages/mako/template.py", line 452, in render_unicode
as_unicode=True)
File "/home/ralsina/.virtualenvs/nikola/local/lib/python2.7/site-packages/mako/runtime.py", line 807, in _render
**_kwargs_for_callable(callable_, data))
File "/home/ralsina/.virtualenvs/nikola/local/lib/python2.7/site-packages/mako/runtime.py", line 839, in _render_context
_exec_template(inherit, lclcontext, args=args, kwargs=kwargs)
File "/home/ralsina/.virtualenvs/nikola/local/lib/python2.7/site-packages/mako/runtime.py", line 865, in _exec_template
callable_(context, *args, **kwargs)
File "/home/ralsina/Desktop/proyectos/static/cache/.mako.tmp/base.tmpl.py", line 141, in render_body
context['self'].content(**pageargs)
File "/home/ralsina/Desktop/proyectos/static/cache/.mako.tmp/index.tmpl.py", line 114, in render_content
__M_writer(unicode(post.text(teaser_only=True)))
File "/home/ralsina/Desktop/proyectos/nikola/master/nikola/post.py", line 462, in text
min_remaining_read=self.messages[lang]["%d min remaining to read"] % (self.remaining_reading_time),
TypeError: not all arguments converted during string formatting

# Fixed code
def load_messages(themes, translations, default_lang):
    """Load theme's messages into context.

    All the messages from parent themes are loaded,
    and "younger" themes have priority.
    """
    messages = Functionary(dict, default_lang)
    oldpath = sys.path[:]
    for theme_name in themes[::-1]:
        msg_folder = os.path.join(get_theme_path(theme_name), "messages")
        default_folder = os.path.join(get_theme_path("base"), "messages")
        sys.path.insert(0, default_folder)
        sys.path.insert(0, msg_folder)
        english = __import__("messages_en")
        for lang in list(translations.keys()):
            try:
                translation = __import__("messages_" + lang)
                # If we don't do the reload, the module is cached
                reload(translation)
                if (
                    sorted(translation.MESSAGES.keys())
                    != sorted(english.MESSAGES.keys())
                    and lang not in warned
                ):
                    warned.append(lang)
                    LOGGER.warn(
                        "Incomplete translation for language '{0}'.".format(lang)
                    )
                messages[lang].update(english.MESSAGES)
                for k, v in translation.MESSAGES.items():
                    if v:
                        messages[lang][k] = v
                del translation
            except ImportError as orig:
                raise LanguageNotFoundError(lang, orig)
    sys.path = oldpath
    return messages