[damned-lies] Fix updating translation for documentation type domains



commit 0d588c98629ac345848108bc925cca821332533c
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Feb 6 18:36:23 2014 +0100

    Fix updating translation for documentation type domains

 stats/models.py      |    6 +++++-
 stats/tests/tests.py |    9 +++++++++
 2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 6ab47f3..96817a7 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -661,7 +661,8 @@ class Branch(models.Model):
 
         locale = language.locale
         commit_dir = os.path.join(self.co_path(), domain.directory)
-        dest_filename = "%s.po" % locale
+        prefix = '' if domain.dtype == 'ui' else locale
+        dest_filename = os.path.join(prefix, "%s.po" % locale)
         dest_path = os.path.join(commit_dir, dest_filename)
         already_exist = os.access(dest_path, os.F_OK)
 
@@ -674,6 +675,9 @@ class Branch(models.Model):
                 'author': author,
                 'msg':     "Updated %s translation" % language.name,
             }
+            if not already_exist and domain.dtype != 'ui':
+                raise Exception("Sorry, adding new translations for documentation is not yet supported.")
+
             with ModuleLock(self.module):
                 utils.run_shell_command(
                     "cd \"%(dest)s\" && git checkout %(branch)s" % var_dict, raise_on_error=True)
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 1dc5fa0..16f5054 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -248,6 +248,15 @@ class ModuleTestCase(TestCase):
             for idx, cmd in enumerate(git_ops):
                 self.assertIn(cmd, cmds[idx])
 
+        domain = self.mod.domain_set.get(name='help')
+        with patch_shell_command() as cmds:
+            branch.commit_po(po_file, domain, lang, 'Author <someone example org>')
+            git_ops = ('git checkout master', 'git pull', 'git add fr/fr.po',
+                       'git commit -m "Updated French translation" --author "Author <someone example org>"',
+                       'git push origin master')
+            for idx, cmd in enumerate(git_ops):
+                self.assertIn(cmd, cmds[idx])
+
     @test_scratchdir
     def test_branch_file_changed(self):
         # file_hashes is empty in fixture, so first call should always return True


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]