def TWtoCN(): with open(getPoPathFromLocale('zh_TW'), 'r') as f: with open(getPoPathFromLocale('zh_CN'), 'w') as fd: for line in f.readlines(): if 'zh_TW' in line: fd.write(line.replace('zh_TW', 'zh_CN')) elif line.startswith('msgstr'): try: fd.write(re.sub('msgstr "(.+)"', lambda m: 'msgstr "%s"' % ftoj(m.group(1)), line)) except UnicodeEncodeError: fd.write(re.sub('msgstr "(.+)"', lambda m: 'msgstr "%s"' % ftoj(m.group(1)), line).encode('utf-8')) else: fd.write(line)
def TWtoCN(): with open(getPoPathFromLocale('zh_TW'), 'r') as f: with open(getPoPathFromLocale('zh_CN'), 'w') as fd: for line in f.readlines(): if 'zh_TW' in line: fd.write(line.replace('zh_TW', 'zh_CN')) elif line.startswith('msgstr'): try: fd.write( re.sub('msgstr "(.+)"', lambda m: 'msgstr "%s"' % ftoj(m.group(1)), line)) except UnicodeEncodeError: fd.write( re.sub('msgstr "(.+)"', lambda m: 'msgstr "%s"' % ftoj(m.group(1)), line).encode('utf-8')) else: fd.write(line)
def getCanonTextTranslation(): canonTextTranslation = {} # initialize canonTextTranslation for dirpath, dirnames, filenames in os.walk(localedir): for dirname in dirnames: locale = dirname path = os.path.join(localedir, '%s/LC_MESSAGES/PaliTextTitle.py' % locale) if os.path.isfile(path): var = imp.load_source('PaliTextTitle', path) canonTextTranslation[locale] = var.PaliTextTitle break # derive zh_CN from zh_TW canonTextTranslation['zh_CN'] = {} for key in canonTextTranslation['zh_TW']: canonTextTranslation['zh_CN'][key] = ftoj(canonTextTranslation['zh_TW'][key]) return canonTextTranslation
def getCanonTextTranslation(): canonTextTranslation = {} # initialize canonTextTranslation for dirpath, dirnames, filenames in os.walk(localedir): for dirname in dirnames: locale = dirname path = os.path.join(localedir, '%s/LC_MESSAGES/PaliTextTitle.py' % locale) if os.path.isfile(path): var = imp.load_source('PaliTextTitle', path) canonTextTranslation[locale] = var.PaliTextTitle break # derive zh_CN from zh_TW canonTextTranslation['zh_CN'] = {} for key in canonTextTranslation['zh_TW']: canonTextTranslation['zh_CN'][key] = ftoj( canonTextTranslation['zh_TW'][key]) return canonTextTranslation
if __name__ == '__main__': dstTrInfoPath = os.path.join(os.path.dirname(__file__), '../pylib/json/translationInfo.json') dstCanonTextTranslationPath = os.path.join(os.path.dirname(__file__), '../pylib/json/canonTextTranslation.json') if not os.path.exists(os.path.dirname(dstTrInfoPath)): os.makedirs(os.path.dirname(dstTrInfoPath)) with open(dstTrInfoPath, 'w') as f: f.write(json.dumps(translationInfo)) canonTextTranslation['zh_CN'] = {} for key in canonTextTranslation['zh_TW']: canonTextTranslation['zh_CN'][key] = ftoj(canonTextTranslation['zh_TW'][key]) with open(dstCanonTextTranslationPath, 'w') as f: f.write(json.dumps(canonTextTranslation)) dstTrServicePath = os.path.join(os.path.dirname(__file__), '../app/scripts/services/data/i18nTpk.js') if not os.path.exists(os.path.dirname(dstTrServicePath)): os.makedirs(os.path.dirname(dstTrServicePath)) with open(dstTrServicePath, 'w') as f: f.write("angular.module('pali.data.i18nTpk', []).\n") f.write(" factory('i18nTpk', [function() {\n") #f.write(" var translationInfo = ") #f.write(json.dumps(translationInfo)) #f.write(";\n") f.write(" var canonTextTranslation = ") f.write(json.dumps(canonTextTranslation))