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.
- Choose a particular page to internationalize.
- Start up Zope 3 and find the location where the page is used.
- 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.
- Make sure the page still renders.
- Create a
localedirectory inside the correspondingViewdirectory, which is usually the parent of the directory the page template is in. - Inside locale create an
enas you should provide English as the native translation. - Inside
encreate a diectory calledLC_MESSAGES. - Create a file called
zope.poin inLC_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.
- Edit the
view.zcmlfile in theViewsdirectory. 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:
- Restart Zope 3.
- 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.
- Pick a package you want to translate.
- Enter the
Viewdirectory inside and proceed to thelocaledirectory. There you best copy theendirectory and name the copy after the language you would like to provide; for examplede. - 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.
- After you are done, make sure the file specifies the right encoding.
- Start Zope 3.
- Set your browser language to the language you prefer.
- Check whether the pages of the package you just edited render in you language.
