summaryrefslogtreecommitdiff
path: root/doc/reference
diff options
context:
space:
mode:
authorMartin Trigaux <mat@odoo.com>2017-11-29 16:40:12 +0100
committerMartin Trigaux <mat@odoo.com>2017-11-29 16:41:19 +0100
commitd87e1a59c031caf6022cf314fb32e44d4790fd9c (patch)
tree8dad1c153cd01709dbc29aa748f9dd48c55b9ad0 /doc/reference
parent046e4ee29e71d9b733fb17715cca49245028b63b (diff)
[IMP] doc: translation documentation
Update screenshot for v11 Give examples of Do/Don't
Diffstat (limited to 'doc/reference')
-rw-r--r--doc/reference/translations.rst97
-rw-r--r--doc/reference/translations/po-export.pngbin6069 -> 12511 bytes
2 files changed, 92 insertions, 5 deletions
diff --git a/doc/reference/translations.rst b/doc/reference/translations.rst
index 16c222ce25c..534853ff7dd 100644
--- a/doc/reference/translations.rst
+++ b/doc/reference/translations.rst
@@ -86,13 +86,100 @@ In JavaScript, the wrapping function is generally :js:func:`odoo.web._t`:
Only literal strings can be marked for exports, not expressions or
variables. For situations where strings are formatted, this means the
- format string must be marked, not the formatted string::
+ format string must be marked, not the formatted string
- # bad, the extract may work but it will not translate the text correctly
- _("Scheduled meeting with %s" % invitee.name)
- # good
- _("Scheduled meeting with %s") % invitee.name
+Variables
+^^^^^^^^^
+**Don't** the extract may work but it will not translate the text correctly::
+
+ _("Scheduled meeting with %s" % invitee.name)
+
+**Do** set the dynamic variables outside of the translation lookup::
+
+ _("Scheduled meeting with %s") % invitee.name
+
+
+Blocks
+^^^^^^
+**Don't** split your translation in several blocks or multiples lines::
+
+ # bad, trailing spaces, blocks out of context
+ _("You have ") + len(invoices) + _(" invoices waiting")
+
+ # bad, multiple small translations
+ _("Reference of the document that generated ") + \
+ _("this sales order request.")
+
+**Do** keep in one block, giving the full context to translators::
+
+ # good, allow to change position of the number in the translation
+ _("You have %s invoices wainting") % len(invoices)
+
+ # good, full sentence is understandable
+ _("Reference of the document that generated " + \
+ "this sales order request.")
+
+Plural
+^^^^^^
+**Don't** pluralize terms the English-way::
+
+ msg = _("You have %s invoice") % invoice_count
+ if invoice_count > 1:
+ msg += _("s")
+
+**Do** keep in mind every language has different plural forms::
+
+ if invoice_count > 1:
+ msg = _("You have %s invoices") % invoice_count
+ else:
+ msg = _("You have %s invoice") % invoice_count
+
+Lazy
+^^^^
+
+**Don't** invoke translation lookup at server launch::
+
+ ERROR_MESSAGE = {
+ # bad, evaluated at server launch with no user language
+ access_error: _('Access Error'),
+ missing_error: _('Missing Record'),
+ }
+
+ class Record(models.Model):
+
+ def _raise_error(self, code):
+ raise UserError(ERROR_MESSAGE[code])
+
+**Don't** invoke translation lookup before loading the translation memory::
+
+ # bad, js _t is evaluated too early
+ var core = require('web.core');
+ var _t = core._t;
+ var map_title = {
+ access_error: _t('Access Error'),
+ missing_error: _t('Missing Record'),
+ };
+
+**Do** evaluate dynamically the translatable content::
+
+ # good, evaluated at run time
+ def _get_error_message():
+ return {
+ access_error: _('Access Error'),
+ missing_error: _('Missing Record'),
+ }
+
+**Do** use `_lt` for lazy-loading::
+
+ # good, js _lt is evaluated lazily
+ var core = require('web.core');
+ var _lt = core._lt;
+ var map_title = {
+ access_error: _lt('Access Error'),
+ missing_error: _lt('Missing Record'),
+ };
+
.. _PO File: http://en.wikipedia.org/wiki/Gettext#Translating
.. _msginit: http://www.gnu.org/software/gettext/manual/gettext.html#Creating
diff --git a/doc/reference/translations/po-export.png b/doc/reference/translations/po-export.png
index 82f8d5ad011..bd7fa14c3d8 100644
--- a/doc/reference/translations/po-export.png
+++ b/doc/reference/translations/po-export.png
Binary files differ