Localization for scripts
Question: I have a new piece of software I'm working on for my company that potentially
will need some localization options for our plant in Mexico. As far as the
application goes, C#/.NET has some great localization features that I will
utilize. The new program will be making use of scripts that will have messages
pop-up to the user, and those are probably the most important ones for
localization. They'll be written in [Iron]Python and we are currently, for
other scripts/software, maintaining two separate scripts for localization (and
some other small changes that could be implemented via logic). What's the best
way to localize a script so we can have just one script?


Answer: The simplest way is to remove all of the user-facing strings from your script,
and instead look up what string is to be shown based on the current language.
For example, instead of:

    
    
    print 'Hello, World'
    

use

    
    
    print _('Hello, World')
    
    def _(key):
        if currentlang == 'es':
            return localized_text_es[key]
        else:
            return key
    
    localized_text_es = { 'Hello, World': '¡Hola, mundo' }
    

You could fill `localized_text` at startup from `en.txt`/`es.txt` files, or
you could hardcode both languages into the scripts, or whatever other method
you choose.

