doc/book/devweb/internationalization.rst
changeset 11735 7a170207acbf
parent 11337 60369010c49e
child 12580 f97eba3156c0
equal deleted inserted replaced
11734:7e2c2354dc99 11735:7a170207acbf
   150 
   150 
   151 1. `cubicweb-ctl i18ncube <cube>`
   151 1. `cubicweb-ctl i18ncube <cube>`
   152 2. Edit the <cube>/i18n/xxx.po  files and add missing translations (empty `msgstr`)
   152 2. Edit the <cube>/i18n/xxx.po  files and add missing translations (empty `msgstr`)
   153 3. `hg ci -m "updated i18n catalogs"`
   153 3. `hg ci -m "updated i18n catalogs"`
   154 4. `cubicweb-ctl i18ninstance <myinstance>`
   154 4. `cubicweb-ctl i18ninstance <myinstance>`
       
   155 
       
   156 
       
   157 Customizing the messages extraction process
       
   158 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       
   159 
       
   160 The messages extraction performed by the ``i18ncommand`` collects messages
       
   161 from a few different sources:
       
   162 
       
   163 - the schema and application definition (entity names, docstrings,
       
   164   help messages, uicfg),
       
   165 
       
   166 - the source files:
       
   167 
       
   168   - ``i18n:content`` or ``i18n:replace`` directives from TAL files (with ``.pt`` extension),
       
   169   - strings prefixed by an underscore (``_``) in python files,
       
   170   - strings with double quotes prefixed by an underscore in javascript files.
       
   171 
       
   172 The source files are collected by walking through the cube directory,
       
   173 but ignoring a few directories like ``.hg``, ``.tox``, ``test`` or
       
   174 ``node_modules``.
       
   175 
       
   176 If you need to customize this behaviour in your cube, you have to
       
   177 extend the ``cubicweb.devtools.devctl.I18nCubeMessageExtractor``. The
       
   178 example below will collect strings from ``jinja2`` files and ignore
       
   179 the ``static`` directory during the messages collection phase::
       
   180 
       
   181   # mymodule.py
       
   182   from cubicweb.devtools import devctl
       
   183 
       
   184   class MyMessageExtractor(devctl.I18nCubeMessageExtractor):
       
   185 
       
   186       blacklist = devctl.I18nCubeMessageExtractor | {'static'}
       
   187       formats = devctl.I18nCubeMessageExtractor.formats + ['jinja2']
       
   188 
       
   189       def collect_jinja2(self):
       
   190           return self.find('.jinja2')
       
   191 
       
   192       def extract_jinja2(self, files):
       
   193           return self._xgettext(files, output='jinja.pot',
       
   194                                 extraopts='-L python --from-code=utf-8')
       
   195 
       
   196 Then, you'll have to register it with a ``cubicweb.i18ncube`` entry point
       
   197 in your cube's setup.py::
       
   198 
       
   199   setup(
       
   200       # ...
       
   201       entry_points={
       
   202           # ...
       
   203           'cubicweb.i18ncube': [
       
   204               'mycube=cubicweb_mycube.mymodule:MyMessageExtractor',
       
   205           ],
       
   206       },
       
   207       # ...
       
   208   )
       
   209 
   155 
   210 
   156 Editing po files
   211 Editing po files
   157 ~~~~~~~~~~~~~~~~
   212 ~~~~~~~~~~~~~~~~
   158 
   213 
   159 Using a PO aware editor
   214 Using a PO aware editor