-
Notifications
You must be signed in to change notification settings - Fork 170
Translations and localisation
You are here: Home · Developing Bika LIMS · Translations and Localisation
- Introduction
- Translating strings in Python code
- Translating strings in javascript code
- Dates and Times
- Overriding translations
- Updating translations
Bika uses zope.i18n and gettext to translate strings. This is the Plone standard, and the process is adapted from several plone addons. Before going any further here, make sure to read:
- [Translating Plone Strings](Translating text strings) in the Plone documentation.
- Internationalization in Plone 3.3 and 4.0
Using _() to return a zope messageid is sufficient if the message is to be printed using TAL or a Plone utility such as plone_utils.addPortalMessage(). In the case of constructed strings, or views which output HTML directly to the browser, UnicodeDecodeError is often encountered. To obtain translated values, and prevent encoding errors, the following must always be considered:
-
Any string values in the mapping parameter dictionary passed to the _() message factory, must be encoded as UTF-8:
new_msg = _("The title is: ${title}", mapping={"title":to_utf8(value)})
-
TAL and friends usually pass the string through translate(), but in python scripts this must be done manually:
translated_msg = context.translate(new_msg)
. This can be done directly with zope.i18n.translate, if it is convienient. -
The resulting value must be UTF-8!
There is a small utility t
in the bika.lims.utils package for obtaining correctly translated strings:
from bika.lims.utils import t
mapping = {"string_value": "hello world"}
value = t(_("Some english string: ${string_value}", mapping=mapping))
print value # translated according to browser headers
Bika uses jarn.jsi18n to translate values in javascript files. Other than initialising the domain catalogs as instructed in the jarn.jsi18n readme, nothing is required.
There are four msgid's in the that need to be overridden to set the Date and Time formats: These messages most probably should be kept translated uniformly across the plone and bika domains.
#. The variables used here are the same as used in the strftime formating.
#. Supported are ${A}, ${a}, ${B}, ${b}, ${H}, ${I}, ${m}, ${d}, ${M}, ${p},
#. ${S}, ${Y}, ${y}, ${Z}, each used as variable in the msgstr.
#. In english speaking countries default is: ${b} ${d}, ${Y} ${I}:${M} ${p}
msgid "date_format_long"
msgstr "${Y}-${m}-${d} ${I}:${M} ${p}"
#. The variables used here are the same as used in the strftime formating.
#. Supported are ${A}, ${a}, ${B}, ${b}, ${H}, ${I}, ${m}, ${d}, ${M}, ${p},
#. ${S}, ${Y}, ${y}, ${Z}, each used as variable in the msgstr.
#. In english speaking countries default is: ${b} ${d}, ${Y}
msgid "date_format_short"
msgstr "${Y}-${m}-${d}"
#. The variables used here are the same as used in the strftime formating.
#. Supported are ${A}, ${a}, ${B}, ${b}, ${H}, ${I}, ${m}, ${d}, ${M}, ${p},
#. ${S}, ${Y}, ${y}, ${Z}, each used as variable in the msgstr.
#. In english speaking countries default is: ${I}:${M} ${p}
#: ./TranslationServiceTool.py
msgid "time_format"
msgstr "${I}:${M} ${p}"
#. Date format used with the datepicker jqueryui plugin.
# The variables used here are **NOT** the same as the strftime formatting. They are taken from the jqueryui datepicker widget's readme, and the available strings are: 'dd', 'mm', 'yy', '-', '/', and '.'
#. Default: "mm/dd/yy"
msgid "date_format_short_datepicker"
msgstr "yy-mm-dd"
To override translations, use the plone-manual.pot and plone-bika.pot files, respectively. Any translation which cannot be automatically discovered during update, or translations which should override the defaults (for example, in packages that extend bika). The references mentioned above make clear which domain contains which type of message, though there are some unavoidable duplications.
In order to rebuild the translation catalogs, you will need the following requirements:
- The gettext package must be installed
- The [update_translatins] and [i18ndude] parts must be copied from buildout.cfg into your local buildout.cfg
- In order to receive the latest translations, or if you want to make a set of translation catalogs to push to git, the transifex client must be correctly installed, and your transifex login name and password must be configured. If you want to use transifex, uncomment 'tx pull' and 'tx push' in bin/buildout.cfg
1) run bin/buildout
2) run bin/update_translations
Done.
User Documentation
- Bika LIMS User Manual
- Releases Changelog
- Community
- How to Contribute
- Supported Instruments
- Results Import from Spreadsheet
- Analysis Requests Import Templates
Hosting and Administration
Developer
- Release Cycle
- Developer Guidelines
- Developing Bika LIMS
- Bika LIMS dev environment
- Translations and localisation
- Instrument Interfacing
- Creating new Report Templates
- Connecting Bika LIMS
Professional Service Providers