doc/book/en/devweb/internationalization.rst
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 12 Jan 2011 14:57:31 +0100
branchstable
changeset 6811 7f89e01d5a6f
parent 5394 105011657405
child 8032 bcb87336c7d2
permissions -rw-r--r--
[doc] stop trying to compile useless files with logilab's internal tools
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
2544
282261b26774 [doc] fixed some dangling internal links
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2539
diff changeset
     3
.. _internationalization:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
2544
282261b26774 [doc] fixed some dangling internal links
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2539
diff changeset
     5
Internationalization
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     6
---------------------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
2539
0f26a76b0348 [doc] some more rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2535
diff changeset
     8
Cubicweb fully supports the internalization of its content and interface.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     9
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    10
Cubicweb's interface internationalization is based on the translation project `GNU gettext`_.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    11
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    12
.. _`GNU gettext`: http://www.gnu.org/software/gettext/
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    13
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    14
Cubicweb' internalization involves two steps:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    15
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    16
* in your Python code and cubicweb-tal templates : mark translatable strings
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    17
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    18
* in your instance : handle the translation catalog, edit translations
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    19
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    20
String internationalization
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    21
~~~~~~~~~~~~~~~~~~~~~~~~~~~
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    22
3992
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    23
User defined string
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    24
```````````````````
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    25
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
In the Python code and cubicweb-tal templates translatable strings can be
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
marked in one of the following ways :
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
 * by using the *built-in* function `_` ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
     class PrimaryView(EntityView):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
         """the full view of an non final entity"""
4751
1a9d2c3c7f0c [book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4442
diff changeset
    33
         __regid__ = 'primary'
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
         title = _('primary')
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
  OR
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
4442
7bc0e4ed4109 fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
    38
 * by using the equivalent request's method ::
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
5222
ed6905d98a5e [doc/book] more flesh to views/primary view
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5137
diff changeset
    40
     class NoResultView(View):
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
         """default view when no result has been found"""
4751
1a9d2c3c7f0c [book] more id -> __regid__
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4442
diff changeset
    42
         __regid__ = 'noresult'
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    43
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
         def call(self, **kwargs):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    45
             self.w(u'<div class="searchMessage"><strong>%s</strong></div>\n'
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4255
diff changeset
    46
                 % self._cw._('No result matching query'))
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    47
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
The goal of the *built-in* function `_` is only **to mark the
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    49
translatable strings**, it will only return the string to translate
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2544
diff changeset
    50
itself, but not its translation (it's actually another name for the
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2544
diff changeset
    51
`unicode` builtin).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    52
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    53
In the other hand the request's method `self._cw._` is also meant to
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    54
retrieve the proper translation of translation strings in the
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    55
requested language.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    56
4442
7bc0e4ed4109 fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
    57
Finally you can also use the `__` attribute of request object to get a
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    58
translation for a string *which should not itself added to the catalog*,
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    59
usually in case where the actual msgid is created by string interpolation ::
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    60
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4255
diff changeset
    61
  self._cw.__('This %s' % etype)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    62
4437
21f2e01fdd6a update exemples using the 3.6 api and add/fix some sections (schema, vreg, talk about CW_MODE in concepts...). So much to do :'(
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4255
diff changeset
    63
In this example ._cw.__` is used instead of ._cw._` so we don't have 'This %s' in
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    64
messages catalogs.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    65
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    66
Translations in cubicweb-tal template can also be done with TAL tags
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
`i18n:content` and `i18n:replace`.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    68
2535
c7b736929a58 [doc] a bit of rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2476
diff changeset
    69
If you need to add messages on top of those that can be found in the source,
c7b736929a58 [doc] a bit of rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2476
diff changeset
    70
you can create a file named `i18n/static-messages.pot`.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    71
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    72
You could put there messages not found in the python sources or
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    73
overrides for some messages of used cubes.
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    74
3992
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    75
Generated string
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    76
````````````````
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    77
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    78
We do not need to mark the translation strings of entities/relations used by a
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    79
particular instance's schema as they are generated automatically. String for
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    80
various actions are also generated.
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    81
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    82
For exemple the following schema ::
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    83
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    84
  Class EntityA(EntityType):
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    85
      relation_a2b = SubjectRelation('EntityB')
3992
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    86
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    87
  class EntityB(EntityType):
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    88
      pass
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    89
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    90
May generate the following message ::
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    91
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    92
  add EntityA relation_a2b EntityB subject
3992
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    93
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    94
This message will be used in views of ``EntityA`` for creation of a new
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    95
``EntityB`` with a preset relation ``relation_a2b`` between the current
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    96
``EntityA`` and the new ``EntityB``. The opposite message ::
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    97
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
    98
  add EntityA relation_a2b EntityB object
3992
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
    99
4255
9d9400cb3f8c update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3992
diff changeset
   100
Is used for similar creation of an ``EntityA`` from a view of ``EntityB``. The
9d9400cb3f8c update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3992
diff changeset
   101
title of they respective creation form will be ::
9d9400cb3f8c update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3992
diff changeset
   102
9d9400cb3f8c update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3992
diff changeset
   103
  creating EntityB (EntityA %(linkto)s relation_a2b EntityB)
9d9400cb3f8c update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3992
diff changeset
   104
9d9400cb3f8c update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3992
diff changeset
   105
  creating EntityA (EntityA relation_a2b %(linkto)s EntityA)
3992
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
   106
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
   107
In the translated string you can use ``%(linkto)s`` for reference to the source
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
   108
``entity``.
4c98f0e28429 update i18n doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 3581
diff changeset
   109
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   110
Handling the translation catalog
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   111
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   112
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   113
Once the internationalization is done in your code, you need to populate and
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   114
update the translation catalog. Cubicweb provides the following commands for this
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   115
purpose:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   116
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   117
1898
39b37f90a8a4 [cw-ctl] rename i18n commands (see #342889)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
   118
* `i18ncubicweb` updates Cubicweb framework's translation
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2544
diff changeset
   119
  catalogs. Unless you actually work on the framework itself, you
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2544
diff changeset
   120
  don't need to use this command.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   122
* `i18ncube` updates the translation catalogs of *one particular cube*
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   123
  (or of all cubes). After this command is executed you must update
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   124
  the translation files *.po* in the "i18n" directory of your
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   125
  cube. This command will of course not remove existing translations
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   126
  still in use. It will mark unused translation but not remove them.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   127
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2544
diff changeset
   128
* `i18ninstance` recompiles the translation catalogs of *one particular
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   129
  instance* (or of all instances) after the translation catalogs of
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   130
  its cubes have been updated. This command is automatically
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   131
  called every time you create or update your instance. The compiled
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   132
  catalogs (*.mo*) are stored in the i18n/<lang>/LC_MESSAGES of
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   133
  instance where `lang` is the language identifier ('en' or 'fr'
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   134
  for exemple).
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   135
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   136
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   137
Example
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   138
```````
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   139
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   140
You have added and/or modified some translation strings in your cube
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   141
(after creating a new view or modifying the cube's schema for exemple).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   142
To update the translation catalogs you need to do:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   143
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   144
1. `cubicweb-ctl i18ncube <cube>`
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   145
2. Edit the <cube>/i18n/xxx.po  files and add missing translations (empty `msgstr`)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   146
3. `hg ci -m "updated i18n catalogs"`
2476
1294a6bdf3bf application -> instance where it makes sense
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1898
diff changeset
   147
4. `cubicweb-ctl i18ninstance <myinstance>`
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   148
5137
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   149
Editing po files
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   150
~~~~~~~~~~~~~~~~
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   151
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   152
Using a PO aware editor
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   153
````````````````````````
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   154
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   155
Many tools exist to help maintain .po (PO) files. Common editors or
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   156
development environment provides modes for these. One can also find
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   157
dedicated PO files editor, such as `poedit`_.
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   158
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   159
.. _`poedit`:  http://www.poedit.net/
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   160
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   161
While usage of such a tool is commendable, PO files are perfectly
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   162
editable with a (unicode aware) plain text editor. It is also useful
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   163
to know their structure for troubleshooting purposes.
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   164
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   165
Structure of a PO file
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   166
``````````````````````
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   167
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   168
In this section, we selectively quote passages of the `GNU gettext`_
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   169
manual chapter on PO files, available there::
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   170
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   171
 http://www.gnu.org/software/hello/manual/gettext/PO-Files.html
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   172
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   173
One PO file entry has the following schematic structure::
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   174
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   175
     white-space
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   176
     #  translator-comments
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   177
     #. extracted-comments
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   178
     #: reference...
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   179
     #, flag...
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   180
     #| msgid previous-untranslated-string
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   181
     msgid untranslated-string
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   182
     msgstr translated-string
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   183
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   184
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   185
A simple entry can look like this::
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   186
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   187
     #: lib/error.c:116
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   188
     msgid "Unknown system error"
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   189
     msgstr "Error desconegut del sistema"
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   190
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   191
It is also possible to have entries with a context specifier. They
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   192
look like this::
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   193
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   194
     white-space
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   195
     #  translator-comments
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   196
     #. extracted-comments
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   197
     #: reference...
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   198
     #, flag...
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   199
     #| msgctxt previous-context
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   200
     #| msgid previous-untranslated-string
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   201
     msgctxt context
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   202
     msgid untranslated-string
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   203
     msgstr translated-string
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   204
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   205
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   206
The context serves to disambiguate messages with the same
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   207
untranslated-string. It is possible to have several entries with the
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   208
same untranslated-string in a PO file, provided that they each have a
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   209
different context. Note that an empty context string and an absent
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   210
msgctxt line do not mean the same thing.
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   211
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   212
Contexts and CubicWeb
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   213
`````````````````````
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   214
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   215
CubicWeb PO files have both non-contextual and contextual msgids.
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   216
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   217
Contextual entries are automatically used in some cases. For instance,
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   218
entity.dc_type(), eschema.display_name(req) or display_name(etype,
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   219
req, form, context) methods/function calls will use them.
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   220
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   221
It is also possible to explicitly use the with _cw.pgettext(context,
efc280ad9898 [doc/book] enhance i18n section #656191
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 4751
diff changeset
   222
msgid).