From 4bc10b6ccbfb98c0ab6415e37cb6577e64dc2106 Mon Sep 17 00:00:00 2001 From: dbs Date: Tue, 20 Nov 2007 20:59:33 +0000 Subject: [PATCH] Use pot2po to generate updated PO files (per asmodai's suggestion). Add a unit test for newpo Makefile target. git-svn-id: svn://svn.open-ils.org/ILS/trunk@8098 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- build/i18n/Makefile | 10 +---- build/i18n/tests/testpo.py | 78 +++++++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 14 deletions(-) diff --git a/build/i18n/Makefile b/build/i18n/Makefile index e3cf385b16..0c154c4cc5 100644 --- a/build/i18n/Makefile +++ b/build/i18n/Makefile @@ -28,7 +28,8 @@ newpot: dtds2pot props2pot 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 @@ dtds2pot: 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 diff --git a/build/i18n/tests/testpo.py b/build/i18n/tests/testpo.py index 3fb85192e7..d2ecdc671c 100644 --- a/build/i18n/tests/testpo.py +++ b/build/i18n/tests/testpo.py @@ -4,6 +4,7 @@ import filecmp import glob import os import re +import shutil import subprocess import sys import unittest @@ -14,17 +15,24 @@ class TestPOFramework(unittest.TestCase): '../../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. @@ -85,6 +93,64 @@ class TestPOFramework(unittest.TestCase): 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() -- 2.43.2