Skip to main content

ZC Buildout recipe for creating i18n utilities

Project description

This recipe generate calls of zope3 i18n utilities i18nextract and i18nmaergeall for collecting and merging msgstr from packages.

Detailed Documentation

I18n Recipe

Parameter

This recipe generate calls of zope3 i18n utilities i18nextract and i18nmaergeall for collecting and merging msgstr from packages.

The recipe has two options:

eggs
The eggs option specified a list of eggs to test given as one ore more setuptools requirement strings. Each string must be given on a separate line.
extra-paths
One or more extra paths to include in the generated i18nextract script.

Example

In Bebop the name of the domain is ‘bebop’, the package is ‘src/bebop’, the output relative to the package is locales, and the location of site.zcml is parts/instance/etc/site.zcml. The buildout snippet looks like:

[i18n]
recipe = iwm.recipe.i18n
eggs = ${testinstance:eggs}
       iwm.recipe.i18n
extra-paths = parts/zope3/src
              parts/zope3/utilities

To re-extract i18n messages from the code execute bin/i18nextract from your buildout directory:

$ bin/i18nextract -d <domain> -p <path> -o <locales> -s <site.zcml>

This will update the <domain>.pot file.

To merge those changes to all existing translations you can do that by executing the bin/i18nmergeall script from your buildout directory:

$ bin/i18nmergeall -l <path>/<locales>

Details

The following text is partly lend from zc.recipe.testrunner.README.txt.

To illustrate this, we’ll create a pair of projects in our sample buildout:

>>> mkdir(sample_buildout, 'demo')
>>> mkdir(sample_buildout, 'demo', 'demo')
>>> write(sample_buildout, 'demo', 'demo', '__init__.py', '')
>>> write(sample_buildout, 'demo', 'setup.py',
... """
... from setuptools import setup
...
... setup(name = "demo")
... """)

>>> mkdir(sample_buildout, 'demo2')
>>> mkdir(sample_buildout, 'demo2', 'demo2')
>>> write(sample_buildout, 'demo2', 'demo2', '__init__.py', '')
>>> write(sample_buildout, 'demo2', 'setup.py',
... """
... from setuptools import setup
...
... setup(name = "demo2", install_requires= ['demoneeded'])
... """)

Demo 2 depends on demoneeded:

>>> mkdir(sample_buildout, 'demoneeded')
>>> mkdir(sample_buildout, 'demoneeded', 'demoneeded')
>>> write(sample_buildout, 'demoneeded', 'demoneeded', '__init__.py', '')
>>> write(sample_buildout, 'demoneeded', 'setup.py',
... """
... from setuptools import setup
...
... setup(name = "demoneeded")
... """)

We’ll update our buildout to install the demo project as a develop egg and to create the test script:

>>> write(sample_buildout, 'buildout.cfg',
... """
... [buildout]
... develop = demo demoneeded demo2
... parts = i18n
... offline = true
...
... [i18n]
... recipe = iwm.recipe.i18n
... eggs =
...    demo
...    demo2
... extra-paths = parts/zope3/src
...               parts/zope3/utilities
... """)

Note that we specified both demo and demo2 in the eggs option and that we put them on separate lines.

We also specified the offline option to run the buildout in offline mode.

Now when we run the buildout:

>>> import os
>>> os.chdir(sample_buildout)
>>> print system(os.path.join(sample_buildout, 'bin', 'buildout') + ' -q'),

We get a i18n script installed in our bin directory:

>>> ls(sample_buildout, 'bin')
-  buildout
-  i18nextract
-  i18nmergeall

We take a look of the content of i18nextract:

>>> cat(sample_buildout, 'bin', 'i18nextract') # doctest:
#!python
<BLANKLINE>
import sys
sys.path[0:0] = [
  '/sample-buildout/demo',
  '/sample-buildout/demo2',
  '/sample-buildout/eggs/zope.testing-X-pyN.N.egg',
  '/sample-buildout/eggs/setuptools-X-pyN.N.egg',
  '/sample-buildout/demoneeded',
  '/sample-buildout/parts/zope3/src',
  '/sample-buildout/parts/zope3/utilities',
  ]
<BLANKLINE>
import os
sys.argv[0] = os.path.abspath(sys.argv[0])
<BLANKLINE>
<BLANKLINE>
import i18nextract
<BLANKLINE>
if __name__ == '__main__':
    i18nextract.main()

And the content of i18nmergeall:

>>> cat(sample_buildout, 'bin', 'i18nmergeall') # doctest:
#!python
<BLANKLINE>
import sys
sys.path[0:0] = [
  '/sample-buildout/demo',
  '/sample-buildout/demo2',
  '/sample-buildout/eggs/zope.testing-X-pyN.N.egg',
  '/sample-buildout/eggs/setuptools-X-pyN.N.egg',
  '/sample-buildout/demoneeded',
  '/sample-buildout/parts/zope3/src',
  '/sample-buildout/parts/zope3/utilities',
  ]
<BLANKLINE>
import os
sys.argv[0] = os.path.abspath(sys.argv[0])
<BLANKLINE>
<BLANKLINE>
import iwm.recipe.i18n.ctl
<BLANKLINE>
if __name__ == '__main__':
    iwm.recipe.i18n.ctl.main_i18nmergeall()

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
iwm.recipe.i18n-0.0.1-py2.4.egg (10.8 kB) Copy SHA256 hash SHA256 Egg 2.4

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page