def test_compile_to_js(self): with tempdir() as workspace: gettextjs.main([TESTDATA_DIR, workspace]) en_js_path = os.path.join( workspace, 'en', 'LC_MESSAGES', 'messages.mo.js' ) with open(en_js_path) as fobj: en_content = fobj.read() prefix_en = '(function (exports) {\n exports.EN_MESSAGES = ' suffix_en = ';\n})(this);' self.assertTrue(en_content.startswith(prefix_en)) self.assertTrue(en_content.endswith(suffix_en)) en_data = json.loads(en_content[len(prefix_en):-len(suffix_en)]) self.assertIn('plural', en_data) self.assertEqual(en_data['plural'], '(n != 1)') self.assertIn('catalog', en_data) self.assertEqual(en_data['catalog'], { 'simple-string': 'A simple string', 'singular-string': [ 'Singular form!', 'Plural form!' ] }) ja_js_path = os.path.join( workspace, 'ja', 'LC_MESSAGES', 'messages.mo.js' ) with open(ja_js_path) as fobj: ja_content = fobj.read() prefix_ja = '(function (exports) {\n exports.JA_MESSAGES = ' suffix_ja = ';\n})(this);' self.assertTrue(ja_content.startswith(prefix_ja)) self.assertTrue(ja_content.endswith(suffix_ja)) ja_data = json.loads(ja_content[len(prefix_ja):-len(suffix_ja)]) self.assertIn('plural', ja_data) self.assertEqual(ja_data['plural'], '0') self.assertIn('catalog', ja_data) self.assertEqual(ja_data['catalog'], { 'simple-string': '簡単なストリング', 'singular-string': ['日本語には複数形がありません。'] })
def test_compile_to_json(self): with tempdir() as workspace: gettextjs.main(['--json', TESTDATA_DIR, workspace]) en_json_path = os.path.join( workspace, 'en', 'LC_MESSAGES', 'messages.mo.json' ) with open(en_json_path) as fobj: en_data = json.load(fobj) self.assertIn('plural', en_data) self.assertEqual(en_data['plural'], '(n != 1)') self.assertIn('catalog', en_data) self.assertEqual(en_data['catalog'], { 'simple-string': 'A simple string', 'singular-string': [ 'Singular form!', 'Plural form!' ] }) ja_json_path = os.path.join( workspace, 'ja', 'LC_MESSAGES', 'messages.mo.json' ) with open(ja_json_path) as fobj: ja_data = json.load(fobj) self.assertIn('plural', ja_data) self.assertEqual(ja_data['plural'], '0') self.assertIn('catalog', ja_data) self.assertEqual(ja_data['catalog'], { 'simple-string': '簡単なストリング', 'singular-string': ['日本語には複数形がありません。'] })