def update_apps_locale(): backdir = os.getcwd() for app_name in settings.INSTALLED_APPS: app = App(app_name) root_path = app.abspath logging.debug('GO=> {0}'.format(root_path)) os.chdir(root_path) # 生成新 eva.po 文件 files = eva.utils.cmd.find_files('.', ['py', 'html']) cmd = 'xgettext --from-code=UTF-8 -L python -k=_ ' + \ ' -o eva.po ' + ' '.join(files) eva.utils.cmd.run_cmd(cmd) # 测试文件是否正确生成 if not os.path.exists('eva.po'): logging.debug('pass {0}'.format(root_path)) continue # 更新 locale 目录中所有语言的 po, mo 文件 update_locales('eva.po', root_path) # 删除 eva.po os.unlink('eva.po') os.chdir(backdir)
def update_site_locales(): root_path = settings.PROJECT_ROOT backdir = os.getcwd() os.chdir(root_path) files = [] for item in settings.SITE_TRANSLATION_FILES: for p in glob.glob(item): if os.path.isdir(p): files.extend( find_files(p, ['py', 'html']) ) else: files.append( p ) cmd = 'xgettext --from-code=UTF-8 -L python -k=_ ' + \ ' --package-name={0}'.format(settings.PACKAGE_NAME) + \ ' --package-version={0}'.format(settings.PACKAGE_VERSION) + \ ' -o eva.po ' + ' '.join(files) run_cmd(cmd) # 测试文件是否正确生成 if not os.path.exists('eva.po'): logging.debug('pass {0}'.format(root_path)) return # 更新 locale 目录中所有语言的 po, mo 文件 update_locales('eva.po', root_path) # 删除 eva.po os.unlink('eva.po') os.chdir(backdir)