[dev] [en] i18n and dynamic menu changes
Goffi
goffi at goffi.org
Dim 29 Déc 21:00:27 CET 2013
G'day,
there are again some important changes in core, concerning
internationalisation (i18n) and dynamic menus:
*** i18n ***
- _() method is not imported anymore in __builtins__ but has to be
explicitly imported from sat.core.i18n. I think it's more clean, and it
avoid errors with tools like pyflakes.
- core.i18n module manage gettext importError, thus is can be used in
Libervia directly
- there id a D_() method for deferred translation. This need some
explanations: xgettext read python sources to find _() method to get
sentences to translate. But xgettext only get python strings. In
addition the _() method return the translated string immediately, this
is not always what we want. D_() allow to say "I want to translate this
sentence, but I'll do it later, so keep the sentence untranslated for now".
Two usecases to be more clear:
* if you have a constants that has to be used for a parameter
category, you want to keep the sentence untranslated, until you actually
display it. This is what is used in
plugins/plugin_misc_text_syntaxes.py: the CATEGORY constant is a
deferred translation like this: CATEGORY = D_("Composition") .
After, the untranslated version is used in TextSyntaxes.params for
category_name (CATEGORY), and the translated one is used for
category_label (_(CATEGORY))
* if you want to dynamically translate a sentence in a other language.
This is the case for menus: Libervia can be used by people speaking
different languages at the same time, so menus need to be translated on
the fly. the getMenus bridge method take a language argument to select
the language.
When using importMenu, you need to give deferred translation for that
(e.g.: (D_('Open'), D_('File')). The untranslated version is used to
check conflicts, while the translated version is returned to the
frontend with menu_path_i18n.
- to do dynamic translations, you can change the translation language
with core.i18n.languageSwitch (dont forget to change back to default
after ! Just use languageSwitch() with no argument)
** menus **
- menus now use generic callback system. When using importMenu, you can
give an actual callback, or the id of an already registered callback (in
this case, you can use additionnal *args and **kwargs as allowed by
registerCallback).
- the extra data parameter is used by menu. e.g. the selected jid for
ITEM_CONTEXT is returned throught these data, with the "jid" key.
- menus are now identified with menu_id (same as callback_id) instead
of (type, category, name) tuples
- paths (array of strings) are used instead of category/name.
e.g. instead of the category "File" and the name "Open", we use the
path ("File", "Open"). This allow to easily create submenus.
- menus are internationalised (see above)
- security_limit is used in the same ways as for parameters.
Next week I will not be available a lot, so the 0.4 is postponed to
begin of january. I still need to refactor XMLUI and fix gateways
(XEP-0100).
Cheer
Goffi
Plus d'informations sur la liste de diffusion dev