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()

Download

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iwm.recipe.i18n-0.0.1-py2.4.egg (10.8 kB view details)

Uploaded Egg

File details

Details for the file iwm.recipe.i18n-0.0.1-py2.4.egg.

File metadata

File hashes

Hashes for iwm.recipe.i18n-0.0.1-py2.4.egg
Algorithm Hash digest
SHA256 fea8d40a2adc7be4a6e8b670fbcc405110c488e04fbd6a7754522810ea5a2f37
MD5 2e23d68af5b0233c7cdf59f138c1d13a
BLAKE2b-256 9bf5d3cbff423c38abb8e6f5d33b35d717cd5f190c3db18075a142965121a7ed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page