[Checkins] SVN: grokproject/trunk/tests.txt Add tests for i18n-scripts.

Uli Fouquet uli at gnufix.de
Tue Sep 23 11:16:40 EDT 2008


Log message for revision 91398:
  Add tests for i18n-scripts.

Changed:
  U   grokproject/trunk/tests.txt

-=-
Modified: grokproject/trunk/tests.txt
===================================================================
--- grokproject/trunk/tests.txt	2008-09-23 14:28:06 UTC (rev 91397)
+++ grokproject/trunk/tests.txt	2008-09-23 15:16:39 UTC (rev 91398)
@@ -30,8 +30,8 @@
     src
     versions.cfg
 
-    >>> sofware_dir = os.path.join(package_dir, 'src', 'grokexample')
-    >>> ls(sofware_dir)
+    >>> software_dir = os.path.join(package_dir, 'src', 'grokexample')
+    >>> ls(software_dir)
     __init__.py
     app.py
     app.txt
@@ -50,6 +50,9 @@
     test...
     zopectl...
 
+Using i18n scripts
+------------------
+
 We can create a POT file out of our sources using the freshly
 generated `i18nextract`::
 
@@ -59,3 +62,96 @@
     domain:...'grokexample'
     ...
     output: '...grokexample.pot'
+
+The .pot file contains no specific entries right now. So let's add a
+source file with translatable content::
+
+    >>> source = """
+    ... from zope.i18nmessageid import MessageFactory
+    ... _ = MessageFactory('grokexample')
+    ...
+    ... class SomeClassWithI18nableContent(object):
+    ...   title = _(u'mytitle')
+    ...   description = _(u'description')
+    ...   name = _(u'name')
+    ... """
+    >>> source_path = os.path.join(software_dir, 'translatable.py')
+    >>> open(source_path, 'w').write(source)
+
+And rerun `bin/i18nextract`::
+
+    >>> cmd = os.path.join(bin_dir, 'i18nextract')
+    >>> output = read_sh(cmd)
+
+The translatable strings now appear in the generated .pot file::
+
+    >>> pot_file = os.path.join(software_dir, 'locales', 'grokexample.pot')
+    >>> print open(pot_file, 'r').read()
+    ####...
+    #: src/grokexample/translatable.py:6
+    msgid "mytitle"
+    msgstr ""
+    <BLANKLINE>
+    #: src/grokexample/translatable.py:7
+    msgid "description"
+    msgstr ""
+    <BLANKLINE>
+    #: src/grokexample/translatable.py:8
+    msgid "name"
+    msgstr ""
+
+Let's now create a translation for that (tiny) set of messages::
+
+    >>> trans_dir_de = os.path.join(software_dir, 'locales', 'de',
+    ...                            'LC_MESSAGES')
+    >>> os.makedirs(trans_dir_de)
+
+In this directory we create a copy of the original .pot file::
+
+    >>> po_file_path = os.path.join(trans_dir_de, 'grokexample.po')
+    >>> po_file = open(pot_file, 'r').read()
+
+We modify the translation to give some more interesting results::
+
+    >>> po_file = po_file.replace('translatable.py:6\n',
+    ...                           'translatable.py:6\n#, fuzzy\n')
+    >>> po_file = po_file.replace('"mytitle"\nmsgstr ""',
+    ...                           '"mytitle"\nmsgstr "Mein Titel"')
+    >>> po_file = po_file.replace('"name"\nmsgstr ""',
+    ...                           '"name"\nmsgstr "Name"')
+    >>> open(po_file_path, 'wb').write(po_file)
+
+We can merge all translations with bin/i18nmergeall::
+
+    >>> cmd = os.path.join(bin_dir, 'i18nmergeall')
+    >>> output = read_sh(cmd).split('\n')
+    >>> print output[1]
+    Merging language "de", domain "grokexample"
+
+We can see the status of translations calling bin/i18nstats::
+
+    >>> cmd = os.path.join(bin_dir, 'i18nstats')
+    >>> output = read_sh(cmd)
+    >>> print output
+    Language    Total    Done    Not Done    Fuzzy      Done %
+    ==========================================================
+    de              3       1           1        1     33.33 %
+
+
+Using the generated `test` script
+---------------------------------
+
+We can run tests::
+
+    >>> cmd = os.path.join(bin_dir, 'test')
+    >>> output = read_sh(cmd)
+    >>> print output
+    Running tests at level 1
+    Running grokexample.FunctionalLayer tests:
+      Set up grokexample.FunctionalLayer in ... seconds.
+      Running:
+    ...
+      Ran 3 tests with 0 failures and 0 errors in ... seconds.
+    Tearing down left over layers:
+      Tear down grokexample.FunctionalLayer ... not supported
+



More information about the Checkins mailing list