Commits

Seraphim Mellos committed 7cc35d8

Fix for PO files with logical ids.

Comments (0)

Files changed (4)

transifex/resources/formats/pofile.py

                     continue
                 # Not pluralized, so no plural rules. Use 5 as 'other'.
                 if ispot:
-                    messages = [(5, entry.msgid)]
+                    messages = [(5, entry.msgstr or entry.msgid)]
                 else:
                     messages = [(5, entry.msgstr)]
 

transifex/resources/tests/lib/pofile/__init__.py

 
         r.delete()
 
+    def test_logical_ids(self):
+        """Test po files with logical ids instead of normal strings"""
+
+
+        # Empty our resource
+        SourceEntity.objects.filter(resource=self.resource).delete()
+
+        # Make sure that we have no suggestions to begin with
+        self.assertEqual(Suggestion.objects.filter(source_entity__in=
+            SourceEntity.objects.filter(resource=self.resource).values('id')).count(), 0)
+
+        # Import file with two senteces
+        handler = POHandler('%s/logical_ids/tests.pot' %
+            os.path.split(__file__)[0])
+        handler.bind_resource(self.resource)
+        handler.set_language(self.resource.source_language)
+        handler.parse_file(is_source=True)
+        handler.save2db(is_source=True)
+
+        # import pt_BR translation
+        handler = POHandler('%s/logical_ids/pt_BR.po' %
+            os.path.split(__file__)[0])
+        handler.bind_resource(self.resource)
+        handler.set_language(self.language)
+        handler.parse_file()
+        handler.save2db()
+
+        # Make sure that we have all translations in the db
+        self.assertEqual(Translation.objects.filter(source_entity__in=
+            SourceEntity.objects.filter(resource=self.resource).values('id')).count(), 2)
+
+        source = SourceEntity.objects.get(resource=self.resource)
+        en_trans = Translation.objects.get(source_entity__resource=self.resource,
+            language = self.resource.source_language)
+        pt_trans = Translation.objects.get(source_entity__resource=self.resource,
+            language = self.language)
+
+        import ipdb; ipdb.set_trace()
+        # Check to see that the correct strings appear as the translations and
+        # not the logical id
+        self.assertEqual(en_trans.string, "Hello, World!")
+        self.assertEqual(pt_trans.string, "Holas, Amigos!")
+        self.assertEqual(source.string, "source_1")
+
     def test_convert_to_suggestions(self):
         """Test convert to suggestions when importing new source files"""
 

transifex/resources/tests/lib/pofile/logical_ids/pt_BR.po

+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-06-08 10:12+0300\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: actionlog/templates/object_action_list.html:7 txpermissions/forms.py:18
+msgid "source_1"
+msgstr "Holas, Amigos!"

transifex/resources/tests/lib/pofile/logical_ids/tests.pot

+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2010-06-08 10:12+0300\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: actionlog/templates/object_action_list.html:7 txpermissions/forms.py:18
+msgid "source_1"
+msgstr "Hello, World!"