def test_dump(self): po_file = PoFile() po_file.add_entry("non translated message") po_file.add_entry("non translated message with plural", "plural") po_file.add_entry("translated message").add_translation("translation") entry_2 = po_file.add_entry("translated message 2", "plural") entry_2.add_plural_translation(0, "translation 2") entry_2.add_plural_translation(1, "plural translation 2") po_file.add_entry("translated message 3", context="context").add_translation("translation 3") entry_4 = po_file.add_entry("translated message 4", "plural", "context") entry_4.add_plural_translation(0, "translation 4") entry_4.add_plural_translation(1, "plural translation 4") entry_5 = po_file.add_entry("translated message 5") entry_5.add_location("filename.py", 42) entry_5.add_location("filename.py", 4242) self.assertEqual( """#. obsolete entry msgid "translated message" msgstr "translation" #. obsolete entry msgid "translated message 2" msgid_plural "plural" msgstr[0] "translation 2" msgstr[1] "plural translation 2" #. obsolete entry msgctxt "context" msgid "translated message 3" msgstr "translation 3" #. obsolete entry msgctxt "context" msgid "translated message 4" msgid_plural "plural" msgstr[0] "translation 4" msgstr[1] "plural translation 4" msgid "translated message 5" msgstr "" """, po_file.dumps(include_locations=False, prune_obsoletes=False)) self.assertEqual( """msgid "translated message 5" msgstr "" """, po_file.dumps(include_locations=False, prune_obsoletes=True)) self.assertEqual( """#: filename.py:42 filename.py:4242 msgid "translated message 5" msgstr "" """, po_file.dumps(include_locations=True, prune_obsoletes=True))
def test_dump_embedded_and_terminal_newlines(self): po_file = PoFile() entry = po_file.add_entry("\nmultiline\nmessage\n", "\nmultiline\nplural\n", "\nmultiline\ncontext\n") entry.add_location("filename.py", 42) entry.add_plural_translation(0, "\ntranslated\nmultiline\nmessage\n") entry.add_plural_translation(1, "\ntranslated\nmultiline\nplural\n") self.assertEqual(r"""msgctxt "" "\n" "multiline\n" "context\n" msgid "" "\n" "multiline\n" "message\n" msgid_plural "" "\n" "multiline\n" "plural\n" msgstr[0] "" "\n" "translated\n" "multiline\n" "message\n" msgstr[1] "" "\n" "translated\n" "multiline\n" "plural\n" """, po_file.dumps(include_locations=False, prune_obsoletes=False))
def test_dump_embedded_and_terminal_newlines(self): po_file = PoFile() entry = po_file.add_entry("\nmultiline\nmessage\n", "\nmultiline\nplural\n", "\nmultiline\ncontext\n") entry.add_location("filename.py", 42) entry.add_plural_translation(0, "\ntranslated\nmultiline\nmessage\n") entry.add_plural_translation(1, "\ntranslated\nmultiline\nplural\n") self.assertEqual( r"""msgctxt "" "\n" "multiline\n" "context\n" msgid "" "\n" "multiline\n" "message\n" msgid_plural "" "\n" "multiline\n" "plural\n" msgstr[0] "" "\n" "translated\n" "multiline\n" "message\n" msgstr[1] "" "\n" "translated\n" "multiline\n" "plural\n" """, po_file.dumps(include_locations=False, prune_obsoletes=False))
def test_dump(self): po_file = PoFile() po_file.add_entry("non translated message") po_file.add_entry("non translated message with plural", "plural") po_file.add_entry("translated message").add_translation("translation") entry_2 = po_file.add_entry("translated message 2", "plural") entry_2.add_plural_translation(0, "translation 2") entry_2.add_plural_translation(1, "plural translation 2") po_file.add_entry("translated message 3", context="context").add_translation("translation 3") entry_4 = po_file.add_entry("translated message 4", "plural", "context") entry_4.add_plural_translation(0, "translation 4") entry_4.add_plural_translation(1, "plural translation 4") entry_5 = po_file.add_entry("translated message 5") entry_5.add_location("filename.py", 42) entry_5.add_location("filename.py", 4242) self.assertEqual("""#. obsolete entry msgid "translated message" msgstr "translation" #. obsolete entry msgid "translated message 2" msgid_plural "plural" msgstr[0] "translation 2" msgstr[1] "plural translation 2" #. obsolete entry msgctxt "context" msgid "translated message 3" msgstr "translation 3" #. obsolete entry msgctxt "context" msgid "translated message 4" msgid_plural "plural" msgstr[0] "translation 4" msgstr[1] "plural translation 4" msgid "translated message 5" msgstr "" """, po_file.dumps(include_locations=False, prune_obsoletes=False)) self.assertEqual("""msgid "translated message 5" msgstr "" """, po_file.dumps(include_locations=False, prune_obsoletes=True)) self.assertEqual("""#: filename.py:42 filename.py:4242 msgid "translated message 5" msgstr "" """, po_file.dumps(include_locations=True, prune_obsoletes=True))
def test_dump_nplurals(self): po_file = PoFile() entry = po_file.add_entry("message", "plural") entry.add_location("filename.py", 42) self.assertEqual("""msgid "message" msgid_plural "plural" msgstr[0] "" msgstr[1] "" """, po_file.dumps(include_locations=False, prune_obsoletes=False)) po_file.add_header_field("Plural-Forms", "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;") self.assertEqual("""msgid "" msgstr "" "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\\n" msgid "message" msgid_plural "plural" msgstr[0] "" msgstr[1] "" msgstr[2] "" """, po_file.dumps(include_locations=False, prune_obsoletes=False))
def test_dump_nplurals(self): po_file = PoFile() entry = po_file.add_entry("message", "plural") entry.add_location("filename.py", 42) self.assertEqual( """msgid "message" msgid_plural "plural" msgstr[0] "" msgstr[1] "" """, po_file.dumps(include_locations=False, prune_obsoletes=False)) po_file.add_header_field( "Plural-Forms", "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;") self.assertEqual( """msgid "" msgstr "" "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\\n" msgid "message" msgid_plural "plural" msgstr[0] "" msgstr[1] "" msgstr[2] "" """, po_file.dumps(include_locations=False, prune_obsoletes=False))