1
2
3
4 from translate.convert import po2php
5 from translate.convert import test_convert
6 from translate.misc import wStringIO
7 from translate.storage import po
8
11 """helper that converts po source to .php source without requiring files"""
12 inputfile = wStringIO.StringIO(posource)
13 inputpo = po.pofile(inputfile)
14 convertor = po2php.po2php()
15 outputphp = convertor.convertstore(inputpo)
16 return outputphp
17
19 """helper that merges po translations to .php source without requiring files"""
20 inputfile = wStringIO.StringIO(posource)
21 inputpo = po.pofile(inputfile)
22 templatefile = wStringIO.StringIO(phpsource)
23
24 convertor = po2php.rephp(templatefile)
25 outputphp = convertor.convertstore(inputpo)
26 print outputphp
27 return outputphp
28
30 """check the simplest case of merging a translation"""
31 posource = '''#: $lang['name']\nmsgid "value"\nmsgstr "waarde"\n'''
32 phptemplate = '''$lang['name'] = 'value';\n'''
33 phpexpected = '''$lang['name'] = 'waarde';\n'''
34 phpfile = self.merge2php(phptemplate, posource)
35 print phpfile
36 assert phpfile == [phpexpected]
37
39 """check that we preserve any spacing in php files when merging"""
40 posource = '''#: $lang['name']\nmsgid "value"\nmsgstr "waarde"\n'''
41 phptemplate = '''$lang['name'] = 'value';\n'''
42 phpexpected = '''$lang['name'] = 'waarde';\n'''
43 phpfile = self.merge2php(phptemplate, posource)
44 print phpfile
45 assert phpfile == [phpexpected]
46
48 """check that we can correctly merge entries that are blank in the template"""
49 posource = '''#: accesskey-accept
50 msgid ""
51 "_: accesskey-accept\n"
52 ""
53 msgstr ""'''
54 phptemplate = '''$lang['accesskey-accept'] = '';\n'''
55 phpexpected = '''$lang['accesskey-accept'] = '';\n'''
56 phpfile = self.merge2php(phptemplate, posource)
57 print phpfile
58 assert phpfile == [phpexpected]
59
61 """check merging a fuzzy translation"""
62 posource = '''#: $lang['name']\n#, fuzzy\nmsgid "value"\nmsgstr "waarde"\n'''
63 phptemplate = '''$lang['name'] = 'value';\n'''
64 phpexpected = '''$lang['name'] = 'value';\n'''
65 phpfile = self.merge2php(phptemplate, posource)
66 print phpfile
67 assert phpfile == [phpexpected]
68
70 """check that a location with spaces in php but spaces removed in PO is used correctly"""
71 posource = '''#: $lang['name']\nmsgid "value"\nmsgstr "waarde"\n'''
72 phptemplate = '''$lang[ 'name' ] = 'value';\n'''
73 phpexpected = '''$lang[ 'name' ] = 'waarde';\n'''
74 phpfile = self.merge2php(phptemplate, posource)
75 print phpfile
76 assert phpfile == [phpexpected]
77
78
79
80
81
82
83
84
85
86
88 """Tests running actual po2php commands on files"""
89 convertmodule = po2php
90 defaultoptions = {"progress": "none"}
91
98