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'
return r
def handle(self, appname, **options):
+ if not options['poname']: options['poname'] = appname
app = __import__(appname)
+
if options['load']:
objects = {}
modmod = {}
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]
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']))
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()
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):
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 = []
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'))