Package Pootle :: Package storage :: Module test_po
[show private | hide private]
[frames | no frames]

Module Pootle.storage.test_po

Function Summary
  test_read_po()
Tests for read_po().
  test_read_po_plurals()
  test_write_po()
We will need a few example units:
  test_write_po_unicode()
We provide proper unicode:

Variable Summary
str sample_po = '# translation of foo\n# Copyright (C) Foo, ...
str sample_po_plurals = '# translation of foo\n#. Plural tes...

Function Details

test_read_po()

Tests for read_po().
>>> from Pootle.storage.po import read_po
>>> store = TranslationStore('foo', None)
>>> read_po(sample_po, store)
>>> store.header.items()
[('Project-Id-Version', u'foo'),
 ('Last-Translator', u'Gintautas Miliauskas <gintas@akl.lt>'),

 ...

('Content-Transfer-Encoding', u'8bit')]
>>> for unit in store:
...     print unit.trans
[(u'Hello', u'Labas')]
>>> store[0].comments['automatic']
[u'Something', u'Anything else.']

>>> store[0].comments['source']
[u'../hello.c:5']

test_read_po_plurals()

>>> from Pootle.storage.po import read_po
>>> store = TranslationStore('foo', None)
>>> read_po(sample_po_plurals, store)
>>> for unit in store:
...     print unit.trans
[(u'One', u'Vienas'), (u'Many', u'Keli'), (u'Many', u'Daug')]

>>> print store[0].comments['automatic']
[u'Plural test']

test_write_po()

We will need a few example units:
>>> store = TranslationStore('foo', None)
>>> store.header['Project-Id-Version'] = 'sample'
>>> store.header['Plural-Forms'] = 'nplurals=1; plural=0;'
>>> store.header['POT-Creation-Date'] = '2006-08-05 22:35+0300\n'
>>> store.header['Last-Translator'] = 'Gintautas Miliauskas <gintas@akl.lt>'
>>> t1 = store.makeunit([('simple', 'einfach')])
>>> t2 = store.makeunit([('spirit', 'der Geist'),
...                      ('spirits', 'die Geiste')])
>>> t2.comments.add('type', 'fuzzy')
>>> t2.comments.add('automatic', 'roboto')
>>> store.fill([t1, t2])
Now let's convert all this to a .po file:
>>> from Pootle.storage.po import write_po
>>> print write_po(store) # doctest: +REPORT_UDIFF
msgid ""
msgstr ""
"Project-Id-Version: sample\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-08-05 22:35+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Gintautas Miliauskas <gintas@akl.lt>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: ENCODING\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Translate Toolkit ...\n"
<BLANKLINE>
msgid "simple"
msgstr "einfach"
<BLANKLINE>
#. roboto
#, fuzzy
msgid "spirit"
msgid_plural "spirits"
msgstr[0] "der Geist"
msgstr[1] "die Geiste"
<BLANKLINE>

test_write_po_unicode()

>>> store = TranslationStore('foo', None)
We provide proper unicode:
>>> t1 = store.makeunit([(u'm\xfcssen', u'prival\u0117ti')])
>>> store.fill([t1])
>>> from Pootle.storage.po import write_po
Output is encoded to UTF-8:
>>> lines = write_po(store).splitlines()
>>> print lines[-2:]
['msgid "m\xc3\xbcssen"', 'msgstr "prival\xc4\x97ti"']

Variable Details

sample_po

Type:
str
Value:
'''# translation of foo
# Copyright (C) Foo, Inc.
# Gintautas Miliauskas <gintas@akl.lt>, 2006.
msgid ""
msgstr ""
"Project-Id-Version: foo\
"
"Last-Translator: Gintautas Miliauskas <gintas@akl.lt>\
...                                                                    

sample_po_plurals

Type:
str
Value:
'''# translation of foo
#. Plural test
msgid "One"
msgid_plural "Many"
msgstr[0] "Vienas"
msgstr[1] "Keli"
msgstr[2] "Daug"
'''                                                                    

Generated by Epydoc 2.1 on Tue Aug 22 04:29:46 2006 http://epydoc.sf.net