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

Proposed by Данило Шеган
Status: Merged
Approved by: Данило Шеган
Approved revision: no longer in the source branch.
Merged at revision: 12107
Proposed branch: lp:~danilo/launchpad/bug-676011
Merge into: lp:launchpad
Diff against target: 87 lines (+36/-5)
2 files modified
lib/lp/translations/model/translationimportqueue.py (+11/-0)
lib/lp/translations/tests/test_translationimportqueue.py (+25/-5)
To merge this branch: bzr merge lp:~danilo/launchpad/bug-676011
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+44066@code.launchpad.net

Commit message

[r=bac][ui=none][bug=676011] Support language variant translations for KDE in source package uploads (especially sr@latin, sr@ijekavian, sr@ijekavianlatin).

Description of the change

= 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

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/translations/model/translationimportqueue.py'
2--- lib/lp/translations/model/translationimportqueue.py 2010-12-17 14:03:32 +0000
3+++ lib/lp/translations/model/translationimportqueue.py 2010-12-18 10:10:48 +0000
4@@ -652,6 +652,17 @@
5
6 lang_code = re.sub(
7 kde_prefix_pattern, '', self.sourcepackagename.name)
8+
9+ path_components = os.path.normpath(self.path).split(os.path.sep)
10+ # Top-level directory (path_components[0]) is something like
11+ # "source" or "messages", and only then comes the
12+ # language code: we generalize it so it supports language code
13+ # in any part of the path.
14+ for path_component in path_components:
15+ if path_component.startswith(lang_code + '@'):
16+ # There are language variants inside a language pack.
17+ lang_code = path_component
18+ break
19 lang_code = lang_mapping.get(lang_code, lang_code)
20 elif (self.sourcepackagename.name == 'koffice-l10n' and
21 self.path.startswith('koffice-i18n-')):
22
23=== modified file 'lib/lp/translations/tests/test_translationimportqueue.py'
24--- lib/lp/translations/tests/test_translationimportqueue.py 2010-12-17 14:06:07 +0000
25+++ lib/lp/translations/tests/test_translationimportqueue.py 2010-12-18 10:10:48 +0000
26@@ -3,8 +3,7 @@
27
28 __metaclass__ = type
29
30-import posixpath
31-
32+import os.path
33 import transaction
34 from zope.component import getUtility
35
36@@ -254,13 +253,14 @@
37 distroseries=self.distroseries)
38 return (l10n_sourcepackage, pot)
39
40- def _getGuessedPOFile(self, source_name, template_name):
41+ def _getGuessedPOFile(self, source_name, template_path):
42 """Return new POTemplate and matched POFile for package and template.
43 """
44+ template_name = os.path.basename(template_path)
45 package, pot = self.createSourcePackageAndPOTemplate(
46 source_name, template_name)
47 queue_entry = self.queue.addOrUpdateEntry(
48- '%s.po' % template_name, template_name, True, self.uploaderperson,
49+ '%s.po' % template_path, template_name, True, self.uploaderperson,
50 distroseries=package.distroseries,
51 sourcepackagename=package.sourcepackagename)
52 pofile = queue_entry.getGuessedPOFile()
53@@ -295,6 +295,26 @@
54 self.assertEquals(potemplate, pofile.potemplate)
55 self.assertEquals(catalan_valencia, pofile.language)
56
57+ def test_KDE4_language_subvariant(self):
58+ # PO file 'sr@test/something.po' in a package named like
59+ # 'kde-l10n-sr' belong in the 'something' translation domain
60+ # for "sr@test" language translations.
61+ serbian_test = self.factory.makeLanguage('sr@test')
62+ potemplate, pofile = self._getGuessedPOFile(
63+ 'kde-l10n-sr', 'sr@test/template')
64+ self.assertEquals(potemplate, pofile.potemplate)
65+ self.assertEquals(serbian_test, pofile.language)
66+
67+ def test_KDE4_language_at_sign(self):
68+ # PO file 'blah@test/something.po' in a package named like
69+ # 'kde-l10n-sr' belong in the 'something' translation domain
70+ # for "sr" language translations.
71+ serbian = getUtility(ILanguageSet).getLanguageByCode('sr')
72+ potemplate, pofile = self._getGuessedPOFile(
73+ 'kde-l10n-sr', 'source/blah@test/template')
74+ self.assertEquals(potemplate, pofile.potemplate)
75+ self.assertEquals(serbian, pofile.language)
76+
77
78 class TestProductOwnerEntryImporter(TestCaseWithFactory):
79 """Test entries update when owners change."""
80@@ -355,7 +375,7 @@
81 if extension is not None:
82 filename = "%s.%s" % (filename, extension)
83 if directory is not None:
84- filename = posixpath.join(directory, filename)
85+ filename = os.path.join(directory, filename)
86 content = self.factory.getUniqueString()
87 return (filename, content)
88