예제 #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_load_str_po(self):
        """Test that a str with multibyte uft-8 chars can parsed correctly"""
        MasterTranslation(text=u"This — that", language_code="en").save()
        MasterTranslation(text=u"something something something something translate", language_code="en").save()

        pofile = """%s

msgid "This — that"
msgstr "Deise — dass"
        """ % POFILE

        errors = import_translations_from_po(pofile, "de", "en")
        self.assertEqual(errors, [])
예제 #3
0
    def test_load_str_po(self):
        """Test that a str with multibyte uft-8 chars can parsed correctly"""
        MasterTranslation(text=u"This — that", language_code="en").save()
        MasterTranslation(text=u"something something something something translate", language_code="en").save()

        pofile = """%s

msgid "This — that"
msgstr "Deise — dass"
        """ % POFILE

        errors = import_translations_from_po(pofile, "de", "en")
        self.assertEqual(errors, [])
예제 #4
0
 def test_errors_returned(self):
     errors = import_translations_from_po(POFILE, "de", "en")
     self.assertEqual(len(errors), 1)
     self.assertEqual(errors[0],
         ("Could not find translation: u'something something something something translate', None", "unknown", ""))
예제 #5
0
 def test_errors_returned(self):
     errors = import_translations_from_po(POFILE, "de", "en")
     self.assertEqual(len(errors), 1)
     self.assertEqual(errors[0],
         ("Could not find translation: u'something something something something translate', None", "unknown", ""))
예제 #6
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)