Search code examples
pythongoogle-app-engineinternationalizationgettext

Python gettext i18n have different version of the same language


I have translated my service running on GAE in various language. The code below works.

However, I want to be able to specify also the country. Specifically, I want to be able to use 2 Portuguese translations: pt_PR and pt_BR. (I have already created the 2 folder with the .mo files)

    i18n.get_i18n().set_locale(language)
    localedir = '/'.join((os.path.dirname(__file__), '..', 'locale'))
    try:
        transl = gettext.translation('strings', localedir = localedir, languages = [language])
    except IOError:
        return

    transl.install()

I'm using webapp2 as framework.


Solution

  • It seems that you can pass languages = ["pt_PT"] or ["pt"] for the Portugues translation, ["pt_BR"] for the Brazilian one.