merge changes from locale test branch
authorMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Thu, 29 Mar 2012 11:15:50 +0000 (13:15 +0200)
committerMarcin Koziej <marcin.koziej@nowoczesnapolska.org.pl>
Thu, 29 Mar 2012 11:15:50 +0000 (13:15 +0200)
apps/modeltranslation/management/commands/translation2po.py
apps/wolnelektury_core/management/commands/localepack.py

index 9cb34de..c38d82c 100644 (file)
@@ -45,6 +45,8 @@ class Command(BaseCommand):
     option_list = BaseCommand.option_list + (
         make_option('-d', '--directory', help='Specify which directory should hold generated PO files', dest='directory'),
         make_option('-l', '--load', help='load locales back to source', action='store_true', dest='load', default=False),
     option_list = BaseCommand.option_list + (
         make_option('-d', '--directory', help='Specify which directory should hold generated PO files', dest='directory'),
         make_option('-l', '--load', help='load locales back to source', action='store_true', dest='load', default=False),
+        make_option('-L', '--language', help='locales to load', dest='lang', default=None),
+        make_option('-n', '--poname', help='name of the po file [no extension]', dest='poname', default=None),
         )
     help = 'Export models from app to po files'
     args = 'app'
         )
     help = 'Export models from app to po files'
     args = 'app'
@@ -62,7 +64,9 @@ class Command(BaseCommand):
         return r
 
     def handle(self, appname, **options):
         return r
 
     def handle(self, appname, **options):
+        if not options['poname']: options['poname'] = appname
         app = __import__(appname)
         app = __import__(appname)
+
         if options['load']:
             objects = {}
             modmod = {}
         if options['load']:
             objects = {}
             modmod = {}
@@ -71,8 +75,17 @@ class Command(BaseCommand):
                     objects[md.__name__] = {}
                     modmod['model'] = md
 
                     objects[md.__name__] = {}
                     modmod['model'] = md
 
+<<<<<<< Updated upstream
             for lng in zip(*settings.LANGUAGES)[0]:
                 pofile = os.path.join(options['directory'], lng, appname + '.po')
             for lng in zip(*settings.LANGUAGES)[0]:
                 pofile = os.path.join(options['directory'], lng, appname + '.po')
+=======
+            languages = get_languages(options['lang'])
+
+            for lng in zip(*languages)[0]:
+                pofile = os.path.join(options['directory'], lng, options['poname'] + '.po')
+                if not os.path.exists(pofile): raise OSError('%s po file: %s not found' % (appname, pofile))
+                print pofile
+>>>>>>> Stashed changes
                 po = polib.pofile(pofile)
                 for entry in po:
                     loc, pk = entry.occurrences[0]
                 po = polib.pofile(pofile)
                 for entry in po:
                     loc, pk = entry.occurrences[0]
@@ -111,4 +124,4 @@ class Command(BaseCommand):
             for lng, po in pofiles.items():
                 try: os.makedirs(os.path.join(directory, lng))
                 except OSError: pass
             for lng, po in pofiles.items():
                 try: os.makedirs(os.path.join(directory, lng))
                 except OSError: pass
-                po.save(os.path.join(directory, lng, '%s.po' % appname))
+                po.save(os.path.join(directory, lng, '%s.po' % options['poname']))
index 0ccdb5d..79bcdf4 100644 (file)
@@ -50,8 +50,9 @@ class AppLocale(Locale):
 
     def load(self, input_directory, languages):
         for lc in zip(*languages)[0]:
 
     def load(self, input_directory, languages):
         for lc in zip(*languages)[0]:
-            shutil.copy2(os.path.join(input_directory, lc, self.name + '.po'),
-                         os.path.join(self.path, 'locale', lc, 'LC_MESSAGES', 'django.po'))
+            if os.path.exists(os.path.join(input_directory, lc, self.name + '.po')):
+                shutil.copy2(os.path.join(input_directory, lc, self.name + '.po'),
+                             os.path.join(self.path, 'locale', lc, 'LC_MESSAGES', 'django.po'))
 
     def generate(self, languages):
         wd = os.getcwd()
 
     def generate(self, languages):
         wd = os.getcwd()
@@ -65,14 +66,16 @@ class AppLocale(Locale):
 
 
 class ModelTranslation(Locale):
 
 
 class ModelTranslation(Locale):
-    def __init__(self, appname):
+    def __init__(self, appname, poname=None):
         self.appname = appname
         self.appname = appname
+        self.poname = poname and poname or appname
 
     def save(self, output_directory, languages):
 
     def save(self, output_directory, languages):
-        call_command('translation2po', self.appname, directory=output_directory)
+        call_command('translation2po', self.appname, directory=output_directory, poname=self.poname)
 
     def load(self, input_directory, languages):
 
     def load(self, input_directory, languages):
-        call_command('translation2po', self.appname, directory=input_directory, load=True, lang=','.join(zip(*languages)[0]))
+        call_command('translation2po', self.appname, directory=input_directory,
+                     load=True, lang=','.join(zip(*languages)[0]), poname=self.poname)
 
 
 class CustomLocale(Locale):
 
 
 class CustomLocale(Locale):
@@ -104,7 +107,7 @@ class CustomLocale(Locale):
         for lc in zip(*languages)[0]:
             shutil.copy2(os.path.join(input_directory, lc, self.name + '.po'),
                          self.po_file(lc))
         for lc in zip(*languages)[0]:
             shutil.copy2(os.path.join(input_directory, lc, self.name + '.po'),
                          self.po_file(lc))
-        os.system('pybabel compile -D django -d %s' % os.dirname(self.out_file))
+        os.system('pybabel compile -D django -d %s' % os.path.dirname(self.out_file))
 
 
 SOURCES = []
 
 
 SOURCES = []
@@ -117,7 +120,7 @@ for appn in settings.INSTALLED_APPS:
         except LookupError, e:
             print "no locales in %s" % app.__name__
 
         except LookupError, e:
             print "no locales in %s" % app.__name__
 
-SOURCES.append(ModelTranslation('infopages'))
+SOURCES.append(ModelTranslation('infopages', 'infopages_db'))
 SOURCES.append(CustomLocale(os.path.dirname(allauth.__file__), name='contrib'))
 
 
 SOURCES.append(CustomLocale(os.path.dirname(allauth.__file__), name='contrib'))