← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~danilo/launchpad/bug-676011 into lp:launchpad

 

Данило Шеган has proposed merging lp:~danilo/launchpad/bug-676011 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #676011 Serbian KDE translations mixed-up
  https://bugs.launchpad.net/bugs/676011


= Bug 676011 =

KDE translations are handled as a special case in Launchpad because they are all split up into separate per-language packages (compared to other software, where all language translations come with the actual source code).

For "variant" translations KDE used to package them into separate packages as well, but for a while now has stopped doing that (well, mostly: it's still somewhat arbitrary).  Instead, they put them into the base language package and instead put all the variant translations inside a subdirectory with top-level directory name being 'language@variant'.

== Proposed fix ==

For a kde-l10n-LANG sourcepackage uploads where uploads contain files like 'something/LANG@VARIANT/.../template.po' treat those as LANG@VARIANT language translations instead of using LANG.

== Tests ==

bin/test -cvvt KDE4_language

== Demo and Q/A ==

Try re-uploading kde-l10n-sr package through Soyuz and track the +imports page to see what languages are assigned to PO files (at the moment, they are all put into Serbian language).

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/translations/model/translationimportqueue.py
  lib/lp/translations/tests/test_translationimportqueue.py
-- 
https://code.launchpad.net/~danilo/launchpad/bug-676011/+merge/44066
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~danilo/launchpad/bug-676011 into lp:launchpad.
=== modified file 'lib/lp/translations/model/translationimportqueue.py'
--- lib/lp/translations/model/translationimportqueue.py	2010-12-01 11:26:57 +0000
+++ lib/lp/translations/model/translationimportqueue.py	2010-12-17 16:54:07 +0000
@@ -652,6 +652,17 @@
 
             lang_code = re.sub(
                 kde_prefix_pattern, '', self.sourcepackagename.name)
+
+            path_components = os.path.normpath(self.path).split(os.path.sep)
+            # Top-level directory (path_components[0]) is something like
+            # "source" or "messages", and only then comes the
+            # language code: we generalize it so it supports language code
+            # in any part of the path.
+            for path_component in path_components:
+                if path_component.startswith(lang_code + '@'):
+                    # There are language variants inside a language pack.
+                    lang_code = path_component
+                    break
             lang_code = lang_mapping.get(lang_code, lang_code)
         elif (self.sourcepackagename.name == 'koffice-l10n' and
               self.path.startswith('koffice-i18n-')):

=== modified file 'lib/lp/translations/tests/test_translationimportqueue.py'
--- lib/lp/translations/tests/test_translationimportqueue.py	2010-11-03 06:14:23 +0000
+++ lib/lp/translations/tests/test_translationimportqueue.py	2010-12-17 16:54:07 +0000
@@ -3,6 +3,7 @@
 
 __metaclass__ = type
 
+import os.path
 import transaction
 from zope.component import getUtility
 
@@ -251,13 +252,14 @@
             distroseries=self.distroseries)
         return (l10n_sourcepackage, pot)
 
-    def _getGuessedPOFile(self, source_name, template_name):
+    def _getGuessedPOFile(self, source_name, template_path):
         """Return new POTemplate and matched POFile for package and template.
         """
+        template_name = os.path.basename(template_path)
         package, pot = self.createSourcePackageAndPOTemplate(
             source_name, template_name)
         queue_entry = self.queue.addOrUpdateEntry(
-            '%s.po' % template_name, template_name, True, self.uploaderperson,
+            '%s.po' % template_path, template_name, True, self.uploaderperson,
             distroseries=package.distroseries,
             sourcepackagename=package.sourcepackagename)
         pofile = queue_entry.getGuessedPOFile()
@@ -292,6 +294,26 @@
         self.assertEquals(potemplate, pofile.potemplate)
         self.assertEquals(catalan_valencia, pofile.language)
 
+    def test_KDE4_language_subvariant(self):
+        # PO file 'sr@test/something.po' in a package named like
+        # 'kde-l10n-sr' belong in the 'something' translation domain
+        # for "sr@test" language translations.
+        serbian_test = self.factory.makeLanguage('sr@test')
+        potemplate, pofile = self._getGuessedPOFile(
+            'kde-l10n-sr', 'sr@test/template')
+        self.assertEquals(potemplate, pofile.potemplate)
+        self.assertEquals(serbian_test, pofile.language)
+
+    def test_KDE4_language_at_sign(self):
+        # PO file 'blah@test/something.po' in a package named like
+        # 'kde-l10n-sr' belong in the 'something' translation domain
+        # for "sr" language translations.
+        serbian = getUtility(ILanguageSet).getLanguageByCode('sr')
+        potemplate, pofile = self._getGuessedPOFile(
+            'kde-l10n-sr', 'source/blah@test/template')
+        self.assertEquals(potemplate, pofile.potemplate)
+        self.assertEquals(serbian, pofile.language)
+
 
 class TestProductOwnerEntryImporter(TestCaseWithFactory):
     """Test entries update when owners change."""


Follow ups