summaryrefslogtreecommitdiff
path: root/test/ext
diff options
context:
space:
mode:
authorRoman Imankulov <roman.imankulov@gmail.com>2015-10-13 11:44:18 +0000
committerRoman Imankulov <roman.imankulov@gmail.com>2015-10-13 16:26:07 +0000
commitd838e4496bb573c252253722401e4f05f55db0e6 (patch)
tree2c2e6b5cd25542b3160a20a9ac9c926f1a30dcf6 /test/ext
parent72e95faf46665753247796df7403c3b49bfe092d (diff)
downloadmako-d838e4496bb573c252253722401e4f05f55db0e6.tar.gz
Ensure babel i18n extactor works properly with non-ascii input
If mako templates contain something like "_('Köln')", babel extractor converts it to pure ASCII so that resulting .po file would contain "K\xf6ln". Not all translation tools and translations are ready for such kind of escape sequences. Babel allows message ids to be non-ascii, the plugin just has to return Unicode objects instead of ASCII strings (and that's exactly how Babel built-in Python and JavaScript extractors work). This fix ensures mako extractor doesn't excape non-ascii symbols, works well both for Unicode and non-unicode input (there is a test for cp1251 encoding), and also provides a workaround for babel charset detector python-babel/babel#274.
Diffstat (limited to 'test/ext')
-rw-r--r--test/ext/test_babelplugin.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/ext/test_babelplugin.py b/test/ext/test_babelplugin.py
index 3789b58..abce70a 100644
--- a/test/ext/test_babelplugin.py
+++ b/test/ext/test_babelplugin.py
@@ -78,3 +78,16 @@ class ExtractMakoTestCase(TemplateTest):
(99, '_', 'No action at a distance.', []),
]
self.assertEqual(expected, messages)
+
+ @skip()
+ def test_extract_utf8(self):
+ mako_tmpl = open(os.path.join(template_base, 'gettext_utf8.mako'), 'rb')
+ message = next(extract(mako_tmpl, {'_', None}, [], {'encoding': 'utf-8'}))
+ assert message == (1, '_', u'K\xf6ln', [])
+
+ @skip()
+ def test_extract_cp1251(self):
+ mako_tmpl = open(os.path.join(template_base, 'gettext_cp1251.mako'), 'rb')
+ message = next(extract(mako_tmpl, {'_', None}, [], {'encoding': 'cp1251'}))
+ # "test" in Rusian. File encoding is cp1251 (aka "windows-1251")
+ assert message == (1, '_', u'\u0442\u0435\u0441\u0442', [])