[open-ils-commits] r8098 - in trunk/build/i18n: . tests

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Nov 20 16:17:09 EST 2007


Author: dbs
Date: 2007-11-20 15:59:33 -0500 (Tue, 20 Nov 2007)
New Revision: 8098

Modified:
   trunk/build/i18n/Makefile
   trunk/build/i18n/tests/testpo.py
Log:
Use pot2po to generate updated PO files (per asmodai's suggestion).
Add a unit test for newpo Makefile target.


Modified: trunk/build/i18n/Makefile
===================================================================
--- trunk/build/i18n/Makefile	2007-11-20 17:07:12 UTC (rev 8097)
+++ trunk/build/i18n/Makefile	2007-11-20 20:59:33 UTC (rev 8098)
@@ -28,7 +28,8 @@
 newproject: po2dtds po2props
 	@echo "Generated newly translated project files for locale $(LOCALE)"
 
-updatepo: update_po_dtds update_po_props
+updatepo: 
+	@pot2po $(PROGRESS) -o $(POOUTDIR)/$(LOCALE) -i $(POOUTDIR) -t $(POOUTDIR)/$(LOCALE) 2>&1
 	@echo "Updated PO files for locale $(LOCALE)"
 
 updateproject: update_moz_dtds update_moz_props
@@ -46,13 +47,6 @@
 props2pot:
 	@moz2po -P $(PROGRESS) -o $(POOUTDIR) -i $(PROPSDIR)/en-US/ 2>&1
 
-
-update_po_dtds:
-	@moz2po $(PROGRESS) -o $(POOUTDIR)/$(LOCALE) -t $(DTDDIR)/en-US/ -i $(DTDDIR)/$(LOCALE)/ 2>&1
-
-update_po_props:
-	@moz2po $(PROGRESS) -o $(POOUTDIR)/$(LOCALE) -t $(PROPSDIR)/en-US/ -i $(PROPSDIR)/$(LOCALE)/ 2>&1
-
 po2dtds:
 	@po2moz $(PROGRESS) -o locale/$(LOCALE) -t $(DTDDIR)/en-US/ -i $(POINDIR)/$(LOCALE) 2>&1
 

Modified: trunk/build/i18n/tests/testpo.py
===================================================================
--- trunk/build/i18n/tests/testpo.py	2007-11-20 17:07:12 UTC (rev 8097)
+++ trunk/build/i18n/tests/testpo.py	2007-11-20 20:59:33 UTC (rev 8098)
@@ -4,6 +4,7 @@
 import glob
 import os
 import re
+import shutil
 import subprocess
 import sys
 import unittest
@@ -14,18 +15,25 @@
         '../../Open-ILS/xul/staff_client/chrome/locale/en-US/*.properties')
 
     def setUp(self):
+        self.tearDown()
         devnull = open('/dev/null', 'w')
         proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'newpo'), 0, None, None, devnull, devnull).wait()
         proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'newproject'), 0, None, None, devnull, devnull).wait()
+        devnull.close()
 
     def tearDown(self):
-        for file in os.listdir('po/ll-LL/'):
-            os.remove(os.path.join('po/ll-LL', file))
-        os.rmdir('po/ll-LL/')
-        for file in os.listdir('locale/ll-LL/'):
-            os.remove(os.path.join('locale/ll-LL/', file))
-        os.rmdir('locale/ll-LL/')
+        tmpdirs = ('po/ll-LL', 'locale/ll-LL')
+        tmpfiles = ('po/test.properties.pot', 'locale/ll-LL/temp.properties.po')
+        for dir in tmpdirs:
+            if os.access(dir, os.F_OK):
+                for file in os.listdir(dir):
+                    os.remove(os.path.join(dir, file))
+                os.rmdir(dir)
 
+        for file in tmpfiles:
+            if os.access(file, os.F_OK):
+                os.remove(file)
+
     def testnewpofiles(self):
         # Create a brand new set of PO files from our en-US project files.
         # Compare the files generated in the po/ll-LL directory with
@@ -85,6 +93,64 @@
 
         self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
 
+    def testupdatepo(self):
+        # Add strings to a POT file, then ensure that the updated PO files
+        # include the new strings
+
+        # Create the "template" PO file
+        commonpo = 'po/ll-LL/common.properties.po'
+        testpo = 'po/ll-LL/test.properties.po'
+        commonfile = open(commonpo)
+        testfile = open(testpo, 'w')
+        for line in commonfile:
+            line = re.sub(r'common.properties$', r'test.properties', line)
+            testfile.write(line)
+        commonfile.close()
+        testfile.close()
+
+        # Create the test POT file
+        commonpot = 'po/common.properties.pot'
+        testpot = 'po/test.properties.pot'
+        commonfile = open(commonpot)
+        testfile = open(testpot, 'w')
+        for line in commonfile:
+            line = re.sub(r'common.properties$', r'test.properties', line)
+            testfile.write(line)
+        commonfile.close()
+        testfile.write("\n#: common.testupdatepo")
+        testfile.write('\nmsgid "TESTUPDATEPO"')
+        testfile.write('\nmsgstr ""')
+        testfile.close()
+
+        # Update the PO files to get the translated strings in place
+        devnull = open('/dev/null', 'w')
+        proc = subprocess.Popen(('make', 'LOCALE=ll-LL', 'updatepo'), 0, None, None, devnull, devnull).wait()
+
+        commonprops = 'po/ll-LL/common.properties.po'
+        tempprops = 'po/ll-LL/temp.properties.po'
+        testprops = 'po/ll-LL/test.properties.po'
+
+        # Munge the common file to make it what we expect it to be
+        commonfile = open(commonprops, 'a+')
+        commonfile.write("\n#: common.testupdatepo")
+        commonfile.write('\nmsgid "TESTUPDATEPO"')
+        commonfile.write('\nmsgstr ""')
+        commonfile.close()
+
+        shutil.copyfile(commonprops, tempprops)
+        commonfile = open(commonprops, 'w')
+        tempfile = open(testpot)
+        for line in tempfile:
+            line = re.sub(r'common.properties$', r'test.properties', line)
+            line = re.sub(r'^"Project-Id-Version: .*"$', r'"Project-Id-Version: PACKAGE VERSION\\n"', line)
+            commonfile.write(line)
+        commonfile.write("\n")
+        commonfile.close()
+        tempfile.close()
+
+        # Compare the updated PO files - they should be the same
+        self.assertEqual(filecmp.cmp(commonprops, testprops), 1)
+
 if __name__ == '__main__':
     os.chdir('..')
     unittest.main()



More information about the open-ils-commits mailing list