HowToDoI18nAndL10nForZope3

How to internationalize and localize Zope 3 Page Templates

What is I18n (Internationalization) and how to do it?

"Official" Definition: Internationalization (I18N) refers to the operation by which a program is made aware of multiple languages.

In our case this requires us to add the new Page Template i18n namespace attributes to the code. Here are detailed descriptions of the attributes: ZPTInternationalizationSupport. Examples of usage can be found in the source code under Zope3/lib/python/Zope/I18n/Views/Browser/whatever.pt.

  1. Choose a particular page to internationalize.
  2. Start up Zope 3 and find the location where the page is used.
  3. Tag the page with i18n attributes. Please use sensable message ids. Often copying the existing English word is not good! For example if you have a button that says "Delete" do not use "Delete" as message id but "delete_button" for example. If you have doubts about the id, come to IRC (irc.freenode.net #zope3-i18n) or send an E-mail to zip@zope.org.

    There are some simple examples in ZPTInternationalizationExamples or you can look at the code in Zope3/lib/python/Zope/I18n/Views/Browser/whatever.pt for more examples.

  4. Make sure the page still renders.
  5. Create a locale directory inside the corresponding View directory, which is usually the parent of the directory the page template is in.
  6. Inside locale create an en as you should provide English as the native translation.
  7. Inside en create a diectory called LC_MESSAGES.
  8. Create a file called zope.po in in LC_MESSAGES. This file should be a typical gettext PO file of the following format:
             msgid ""
             msgstr ""
             "Project-Id-Version: Zope 3\n"
             "PO-Revision-Date: 2002/06/15 07:01\n"
             "Last-Translator: Zope 3 Contributors\n"
             "Zope-Language: en\n"
             "Zope-Domain: default\n" 
             "MIME-Version: 1.0\n"
             "Content-Type: text/plain; charset=UTF-8\n"
             "Content-Transfer-Encoding: 8bit\n"
    
             msgid "delete_button"
             msgstr "Delete"
    

Note: I really would prefer the translations to be in UTF-8, but you can also use Latin-1 (ISO-8859-1), if you like.

  1. Edit the view.zcml file in the Views directory. Add the following gts namespace on top and add the following directive:
             <gts:registerTranslations directory="./locale" />
    

After you are done the file might look like this:

  1. Restart Zope 3.
  2. Now you can check whether your page is rendered correctly using the provided translations.

What is L10n (Localization) and how to do it?

Localization (L10N) refers to the adaptation of your program, once internationalized, to the local language and cultural habits.

Currently we have only file-based page templates, and therefore all translations will be stored in files too. I chose to use the gettext format for the representation, since a lot of tools exist for it already.

  1. Pick a package you want to translate.
  2. Enter the View directory inside and proceed to the locale directory. There you best copy the en directory and name the copy after the language you would like to provide; for example de.
  3. Enter your language's directory, then LC_MESSAGES and then edit zope.po. Please edit only the message string, not the message id, even though it might be mispelled.
  4. After you are done, make sure the file specifies the right encoding.
  5. Start Zope 3.
  6. Set your browser language to the language you prefer.
  7. Check whether the pages of the package you just edited render in you language.



( 97 subscribers )