コード例 #1
0
    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))
コード例 #2
0
 def test_message_with_context(self):
     po_file = PoFile()
     entry = po_file.add_entry("message", context="context")
     self.assertEqual("message", entry.message)
     self.assertEqual("context", entry.context)
     self.assertIn("context\x04message", po_file.entries)
     self.assertIs(entry, po_file.entries["context\x04message"])
コード例 #3
0
 def test_location(self):
     po_file = PoFile()
     entry = po_file.add_entry("message")
     entry.add_location("filename.py", 42)
     entry.add_location("filename.py", 4242)
     self.assertEqual([("filename.py", 42), ("filename.py", 4242)],
                      entry.locations)
コード例 #4
0
 def test_message_with_plural(self):
     po_file = PoFile()
     entry = po_file.add_entry("message", "plural message")
     self.assertEqual("message", entry.message)
     self.assertEqual("plural message", entry.plural)
     self.assertIn("message", po_file.entries)
     self.assertIs(entry, po_file.entries["message"])
コード例 #5
0
 def test_message_with_context(self):
     po_file = PoFile()
     entry = po_file.add_entry("message", context="context")
     self.assertEqual("message", entry.message)
     self.assertEqual("context", entry.context)
     self.assertIn("context\x04message", po_file.entries)
     self.assertIs(entry, po_file.entries["context\x04message"])
コード例 #6
0
    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))
コード例 #7
0
 def test_message_with_plural(self):
     po_file = PoFile()
     entry = po_file.add_entry("message", "plural message")
     self.assertEqual("message", entry.message)
     self.assertEqual("plural message", entry.plural)
     self.assertIn("message", po_file.entries)
     self.assertIs(entry, po_file.entries["message"])
コード例 #8
0
 def test_plural_translation(self):
     po_file = PoFile()
     entry = po_file.add_entry("message", "plural")
     entry.add_plural_translation(0, "translation")
     entry.add_plural_translation(1, "plural translation")
     self.assertEqual({0: "translation", 1: "plural translation"}, entry.translations)
     self.assertEqual(
         {
             ("message", 0): "translation",
             ("message", 1): "plural translation"},
         po_file.get_catalog())
コード例 #9
0
 def test_plural_translation(self):
     po_file = PoFile()
     entry = po_file.add_entry("message", "plural")
     entry.add_plural_translation(0, "translation")
     entry.add_plural_translation(1, "plural translation")
     self.assertEqual({
         0: "translation",
         1: "plural translation"
     }, entry.translations)
     self.assertEqual(
         {
             ("message", 0): "translation",
             ("message", 1): "plural translation"
         }, po_file.get_catalog())
コード例 #10
0
 def test_catalog(self):
     po_file = PoFile()
     po_file.add_entry("non translated message")
     po_file.add_entry("translated message").add_translation("translation")
     entry = po_file.add_entry("translated message 2", "plural")
     entry.add_plural_translation(0, "translation 2")
     entry.add_plural_translation(1, "plural translation 2")
     po_file.add_entry("translated message 3", context="context").add_translation("translation 3")
     entry = po_file.add_entry("translated message 4", "plural", "context")
     entry.add_plural_translation(0, "translation 4")
     entry.add_plural_translation(1, "plural translation 4")
     self.assertEqual(
         {
             "translated message": "translation",
             ("translated message 2", 0): "translation 2",
             ("translated message 2", 1): "plural translation 2",
             "context\x04translated message 3": "translation 3",
             ("context\x04translated message 4", 0): "translation 4",
             ("context\x04translated message 4", 1): "plural translation 4"},
         po_file.get_catalog())
コード例 #11
0
 def test_catalog(self):
     po_file = PoFile()
     po_file.add_entry("non translated message")
     po_file.add_entry("translated message").add_translation("translation")
     entry = po_file.add_entry("translated message 2", "plural")
     entry.add_plural_translation(0, "translation 2")
     entry.add_plural_translation(1, "plural translation 2")
     po_file.add_entry("translated message 3",
                       context="context").add_translation("translation 3")
     entry = po_file.add_entry("translated message 4", "plural", "context")
     entry.add_plural_translation(0, "translation 4")
     entry.add_plural_translation(1, "plural translation 4")
     self.assertEqual(
         {
             "translated message": "translation",
             ("translated message 2", 0): "translation 2",
             ("translated message 2", 1): "plural translation 2",
             "context\x04translated message 3": "translation 3",
             ("context\x04translated message 4", 0): "translation 4",
             ("context\x04translated message 4", 1): "plural translation 4"
         }, po_file.get_catalog())
コード例 #12
0
    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))
コード例 #13
0
    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))
コード例 #14
0
 def test_location(self):
     po_file = PoFile()
     entry = po_file.add_entry("message")
     entry.add_location("filename.py", 42)
     entry.add_location("filename.py", 4242)
     self.assertEqual([("filename.py", 42), ("filename.py", 4242)], entry.locations)
コード例 #15
0
 def test_translation(self):
     po_file = PoFile()
     entry = po_file.add_entry("message")
     entry.add_translation("translation")
     self.assertEqual({0: "translation"}, entry.translations)
     self.assertEqual({"message": "translation"}, po_file.get_catalog())
コード例 #16
0
 def test_translation(self):
     po_file = PoFile()
     entry = po_file.add_entry("message")
     entry.add_translation("translation")
     self.assertEqual({0: "translation"}, entry.translations)
     self.assertEqual({"message": "translation"}, po_file.get_catalog())
コード例 #17
0
    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))
コード例 #18
0
    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))