示例#1
0
    def test_pl_po_manually(self):
        lang = settings.LANGUAGE_CODE
        invalidate_language("pl")
        self.assertEqual(Translation.objects.count(), 0)
        MasterTranslation.objects.create(
            language_code=lang,
            text="%(n)s result",
            plural_text="%(n)s results",
        )
        MasterTranslation.objects.create(
            language_code=lang,
            text="cat",
        )
        mock_file_contents = u'''# Something something
# Translators list
msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-17 11:07+0100\n"
"PO-Revision-Date: 2015-01-18 15:19+0000\n"
"Last-Translator: Janusz Harkot <*****@*****.**>\n"
"Language-Team: Polish (http://www.transifex.com/projects/p/django/language/"
"pl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: pl\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"

#, python-format
msgid "%(n)s result"
msgid_plural "%(n)s results"
msgstr[0] "%(n)s wynik"
msgstr[1] "%(n)s wyniki"
msgstr[2] "%(n)s wyników"

#, python-format
msgid "cat"
msgstr "kot"
'''
        #msgctxt "context hint"
        import_translations_from_po(mock_file_contents, "pl", lang)
        translation.activate("pl")
        self.assertEqual(ngettext("%(n)s result", "", 0).decode('utf-8'), u"%(n)s wyników")
        self.assertEqual(ngettext("%(n)s result", "", 1).decode('utf-8'), u"%(n)s wynik")
        self.assertEqual(ngettext("%(n)s result", "", 2).decode('utf-8'), u"%(n)s wyniki")
        self.assertEqual(ngettext("%(n)s result", "", 5).decode('utf-8'), u"%(n)s wyników")

        # Singlar translation test
        self.assertEqual(gettext("cat"), u"kot")
        # This form is wrong because po don't support the fraction plural form!
        self.assertEqual(ngettext("%(n)s result", "", 0.5).decode('utf-8'), u"%(n)s wyników")  # u")

        self.assertEqual(get_plural_index("pl", 0), cldr.MANY)
        self.assertEqual(get_plural_index("pl", 1), cldr.ONE)
        self.assertEqual(get_plural_index("pl", 2), cldr.FEW)
        self.assertEqual(get_plural_index("pl", 5), cldr.MANY)
        self.assertEqual(get_plural_index("pl", 1.1), cldr.OTHER)
示例#2
0
    def test_pl_arb_manually(self):
        lang = settings.LANGUAGE_CODE
        invalidate_language("pl")
        self.assertEqual(Translation.objects.count(), 0)
        pk1 = MasterTranslation.objects.create(
            language_code=lang,
            text="result",
            plural_text="results",
        ).pk
        pk2 = MasterTranslation.objects.create(
            language_code=lang,
            text="cat",
        ).pk
        data = {
            "@@locale": "pl",
            # two form isn't needed or used by the pl lookup function so it should be ignored
            pk1:
            u"{NUM, plural, one {wynik} few {wyniki} two {blabla} many {wyników} other {wyniku}}",
            "@" + pk1: {
                "context": "",
                "source_text": "result",
                "type": "text"
            },
            pk2: u"kot",
            "@" + pk2: {
                "context": "",
                "source_text": "cat",
                "type": "text"
            },
        }
        mock_file = StringIO(json.dumps(data))
        import_translations_from_arb(mock_file, "pl")

        translation.activate("pl")
        self.assertEqual(ngettext("result", "", 0).decode('utf-8'), u"wyników")
        self.assertEqual(ngettext("result", "", 1).decode('utf-8'), u"wynik")
        self.assertEqual(ngettext("result", "", 2).decode('utf-8'), u"wyniki")
        self.assertEqual(ngettext("result", "", 5).decode('utf-8'), u"wyników")
        self.assertEqual(
            ngettext("result", "", 0.5).decode('utf-8'), u"wyniku")

        # Singlar translation test
        self.assertEqual(gettext("cat"), u"kot")

        self.assertEqual(get_plural_index("pl", 0), cldr.MANY)
        self.assertEqual(get_plural_index("pl", 1), cldr.ONE)
        self.assertEqual(get_plural_index("pl", 2), cldr.FEW)
        self.assertEqual(get_plural_index("pl", 5), cldr.MANY)
        self.assertEqual(get_plural_index("pl", 1.1), cldr.OTHER)
示例#3
0
    def test_pl_arb_manually(self):
        lang = settings.LANGUAGE_CODE
        invalidate_language("pl")
        self.assertEqual(Translation.objects.count(), 0)
        pk1 = MasterTranslation.objects.create(
            language_code=lang,
            text="result",
            plural_text="results",
        ).pk
        pk2 = MasterTranslation.objects.create(
            language_code=lang,
            text="cat",
        ).pk
        data = {
            "@@locale": "pl",
            # two form isn't needed or used by the pl lookup function so it should be ignored
            pk1: u"{NUM, plural, one {wynik} few {wyniki} two {blabla} many {wyników} other {wyniku}}",
            "@"+pk1: {
                "context": "",
                "source_text": "result",
                "type": "text"
            },
            pk2: u"kot",
            "@"+pk2: {
                "context": "",
                "source_text": "cat",
                "type": "text"
            },
        }
        mock_file = StringIO(json.dumps(data))
        import_translations_from_arb(mock_file, "pl")

        translation.activate("pl")
        self.assertEqual(ngettext("result", "", 0).decode('utf-8'), u"wyników")
        self.assertEqual(ngettext("result", "", 1).decode('utf-8'), u"wynik")
        self.assertEqual(ngettext("result", "", 2).decode('utf-8'), u"wyniki")
        self.assertEqual(ngettext("result", "", 5).decode('utf-8'), u"wyników")
        self.assertEqual(ngettext("result", "", 0.5).decode('utf-8'), u"wyniku")

        # Singlar translation test
        self.assertEqual(gettext("cat"), u"kot")

        self.assertEqual(get_plural_index("pl", 0), cldr.MANY)
        self.assertEqual(get_plural_index("pl", 1), cldr.ONE)
        self.assertEqual(get_plural_index("pl", 2), cldr.FEW)
        self.assertEqual(get_plural_index("pl", 5), cldr.MANY)
        self.assertEqual(get_plural_index("pl", 1.1), cldr.OTHER)
示例#4
0
    def test_pl_po_manually(self):
        lang = settings.LANGUAGE_CODE
        invalidate_language("pl")
        self.assertEqual(Translation.objects.count(), 0)
        MasterTranslation.objects.create(
            language_code=lang,
            text="%(n)s result",
            plural_text="%(n)s results",
        )
        MasterTranslation.objects.create(
            language_code=lang,
            text="cat",
        )
        mock_file_contents = u'''# Something something
# Translators list
msgid ""
msgstr ""
"Project-Id-Version: django\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-17 11:07+0100\n"
"PO-Revision-Date: 2015-01-18 15:19+0000\n"
"Last-Translator: Janusz Harkot <*****@*****.**>\n"
"Language-Team: Polish (http://www.transifex.com/projects/p/django/language/"
"pl/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: pl\n"
"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
"|| n%100>=20) ? 1 : 2);\n"

#, python-format
msgid "%(n)s result"
msgid_plural "%(n)s results"
msgstr[0] "%(n)s wynik"
msgstr[1] "%(n)s wyniki"
msgstr[2] "%(n)s wyników"

#, python-format
msgid "cat"
msgstr "kot"
'''
        #msgctxt "context hint"
        import_translations_from_po(mock_file_contents, "pl", lang)
        translation.activate("pl")
        self.assertEqual(
            ngettext("%(n)s result", "", 0).decode('utf-8'), u"%(n)s wyników")
        self.assertEqual(
            ngettext("%(n)s result", "", 1).decode('utf-8'), u"%(n)s wynik")
        self.assertEqual(
            ngettext("%(n)s result", "", 2).decode('utf-8'), u"%(n)s wyniki")
        self.assertEqual(
            ngettext("%(n)s result", "", 5).decode('utf-8'), u"%(n)s wyników")

        # Singlar translation test
        self.assertEqual(gettext("cat"), u"kot")
        # This form is wrong because po don't support the fraction plural form!
        self.assertEqual(
            ngettext("%(n)s result", "", 0.5).decode('utf-8'),
            u"%(n)s wyników")  # u")

        self.assertEqual(get_plural_index("pl", 0), cldr.MANY)
        self.assertEqual(get_plural_index("pl", 1), cldr.ONE)
        self.assertEqual(get_plural_index("pl", 2), cldr.FEW)
        self.assertEqual(get_plural_index("pl", 5), cldr.MANY)
        self.assertEqual(get_plural_index("pl", 1.1), cldr.OTHER)