# Buggy code
def lhandler(default, toconf, show_header=True):
    if show_header:
        print("We will now ask you to provide the list of languages you want to use.")
        print(
            "Please list all the desired languages, comma-separated, using ISO 639-1 codes.  The first language will be used as the default."
        )
        print("Type '?' (a question mark, sans quotes) to list available languages.")
    answer = ask("Language(s) to use", "en")
    while answer.strip() == "?":
        print("\n# Available languages:")
        print(SAMPLE_CONF["_SUPPORTED_LANGUAGES"] + "\n")
        answer = ask("Language(s) to use", "en")

    langs = [i.strip().lower().replace("-", "_") for i in answer.split(",")]
    for partial, full in LEGAL_VALUES["_TRANSLATIONS_WITH_COUNTRY_SPECIFIERS"].items():
        if partial in langs:
            langs[langs.index(partial)] = full
            print("NOTICE: Assuming '{0}' instead of '{1}'.".format(full, partial))

    default = langs.pop(0)
    SAMPLE_CONF["DEFAULT_LANG"] = default
    # format_default_translations_config() is intelligent enough to
    # return the current value if there are no additional languages.
    SAMPLE_CONF["TRANSLATIONS"] = format_default_translations_config(langs)

    # Get messages for navigation_links.  In order to do this, we need
    # to generate a throwaway TRANSLATIONS dict.
    tr = {default: ""}
    for l in langs:
        tr[l] = "./" + l
    # Assuming that base contains all the locales, and that base does
    # not inherit from anywhere.
    try:
        messages = load_messages(["base"], tr, default)
        SAMPLE_CONF["NAVIGATION_LINKS"] = format_navigation_links(
            langs, default, messages
        )
    except nikola.utils.LanguageNotFoundError as e:
        print("    ERROR: the language '{0}' is not supported.".format(e.lang))
        print(
            "    Are you sure you spelled the name correctly?  Names are case-sensitive and need to be reproduced as-is (complete with the country specifier, if any)."
        )
        print("\nType '?' (a question mark, sans quotes) to list available languages.")
        lhandler(default, toconf, show_header=False)


# Traceback (ValueError)
nikola init mysite
[2014-05-25T11:26:12Z] WARNING: Nikola: Could not guess locale for language en, using locale C
Traceback (most recent call last):
File "/home/luca/.local/bin/nikola", line 9, in <module>
load_entry_point('Nikola==7.0.0', 'console_scripts', 'nikola')()
File "/home/luca/.local/lib/python3.4/site-packages/nikola/__main__.py", line 124, in main
site = Nikola(**config)
File "/home/luca/.local/lib/python3.4/site-packages/nikola/nikola.py", line 517, in __init__
self.plugin_manager.collectPlugins()
File "/home/luca/.local/lib/python3.4/site-packages/yapsy/PluginManager.py", line 527, in collectPlugins
self.locatePlugins()
File "/home/luca/.local/lib/python3.4/site-packages/yapsy/PluginManager.py", line 442, in locatePlugins
self._candidates, npc = self.getPluginLocator().locatePlugins()
File "/home/luca/.local/lib/python3.4/site-packages/yapsy/PluginFileLocator.py", line 430, in locatePlugins
plugin_info = self._getInfoForPluginFromAnalyzer(analyzer, dirpath, filename)
File "/home/luca/.local/lib/python3.4/site-packages/yapsy/PluginFileLocator.py", line 384, in _getInfoForPluginFromAnalyzer
plugin_info_dict,config_parser = analyzer.getInfosDictFromPlugin(dirpath, filename)
File "/home/luca/.local/lib/python3.4/site-packages/yapsy/PluginFileLocator.py", line 264, in getInfosDictFromPlugin
raise ValueError("Missing *name* of the plugin in extracted infos.")
ValueError: Missing *name* of the plugin in extracted infos.

# Fixed code
def lhandler(default, toconf, show_header=True):
    if show_header:
        print("We will now ask you to provide the list of languages you want to use.")
        print(
            "Please list all the desired languages, comma-separated, using ISO 639-1 codes.  The first language will be used as the default."
        )
        print("Type '?' (a question mark, sans quotes) to list available languages.")
    answer = ask("Language(s) to use", "en")
    while answer.strip() == "?":
        print("\n# Available languages:")
        try:
            print(SAMPLE_CONF["_SUPPORTED_LANGUAGES"] + "\n")
        except UnicodeEncodeError:
            # avoid Unicode characters in supported language names
            print(unidecode.unidecode(SAMPLE_CONF["_SUPPORTED_LANGUAGES"]) + "\n")
        answer = ask("Language(s) to use", "en")

    langs = [i.strip().lower().replace("-", "_") for i in answer.split(",")]
    for partial, full in LEGAL_VALUES["_TRANSLATIONS_WITH_COUNTRY_SPECIFIERS"].items():
        if partial in langs:
            langs[langs.index(partial)] = full
            print("NOTICE: Assuming '{0}' instead of '{1}'.".format(full, partial))

    default = langs.pop(0)
    SAMPLE_CONF["DEFAULT_LANG"] = default
    # format_default_translations_config() is intelligent enough to
    # return the current value if there are no additional languages.
    SAMPLE_CONF["TRANSLATIONS"] = format_default_translations_config(langs)

    # Get messages for navigation_links.  In order to do this, we need
    # to generate a throwaway TRANSLATIONS dict.
    tr = {default: ""}
    for l in langs:
        tr[l] = "./" + l
    # Assuming that base contains all the locales, and that base does
    # not inherit from anywhere.
    try:
        messages = load_messages(["base"], tr, default)
        SAMPLE_CONF["NAVIGATION_LINKS"] = format_navigation_links(
            langs, default, messages
        )
    except nikola.utils.LanguageNotFoundError as e:
        print("    ERROR: the language '{0}' is not supported.".format(e.lang))
        print(
            "    Are you sure you spelled the name correctly?  Names are case-sensitive and need to be reproduced as-is (complete with the country specifier, if any)."
        )
        print("\nType '?' (a question mark, sans quotes) to list available languages.")
        lhandler(default, toconf, show_header=False)