From: Marcin Koziej Date: Thu, 29 Mar 2012 11:15:50 +0000 (+0200) Subject: merge changes from locale test branch X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/70dd8cb8ca032fbf50592ff391afb3dffd1d2970 merge changes from locale test branch --- diff --git a/apps/modeltranslation/management/commands/translation2po.py b/apps/modeltranslation/management/commands/translation2po.py index 9cb34deca..c38d82c6c 100644 --- a/apps/modeltranslation/management/commands/translation2po.py +++ b/apps/modeltranslation/management/commands/translation2po.py @@ -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), + 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' @@ -62,7 +64,9 @@ class Command(BaseCommand): return r def handle(self, appname, **options): + if not options['poname']: options['poname'] = appname app = __import__(appname) + if options['load']: objects = {} modmod = {} @@ -71,8 +75,17 @@ class Command(BaseCommand): objects[md.__name__] = {} modmod['model'] = md +<<<<<<< Updated upstream 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] @@ -111,4 +124,4 @@ class Command(BaseCommand): 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'])) diff --git a/apps/wolnelektury_core/management/commands/localepack.py b/apps/wolnelektury_core/management/commands/localepack.py index 0ccdb5da3..79bcdf4b7 100644 --- a/apps/wolnelektury_core/management/commands/localepack.py +++ b/apps/wolnelektury_core/management/commands/localepack.py @@ -50,8 +50,9 @@ class AppLocale(Locale): 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() @@ -65,14 +66,16 @@ class AppLocale(Locale): class ModelTranslation(Locale): - def __init__(self, appname): + def __init__(self, appname, poname=None): self.appname = appname + self.poname = poname and poname or appname 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): - 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): @@ -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)) - 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 = [] @@ -117,7 +120,7 @@ for appn in settings.INSTALLED_APPS: 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'))