예제 #1
0
def main():
    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')

    lang_file = os.path.join(translation_path, 'lang/en.lang.csv')
    with open(lang_file, 'rt', encoding='utf-8') as fp:
        fp.readline()
        lines = [LangLine.from_csv_line(line).origin for line in fp.readlines()]

    pregame_file = os.path.join(translation_path, 'en_pregame.lua')
    client_file = os.path.join(translation_path, 'en_client.lua')
    ui_mgr = UiMgr()
    ui_mgr.load_lua_file(pregame_file)
    ui_mgr.load_lua_file(client_file)
    lines.extend([ui_line.origin for ui_line in ui_mgr.ui_lines.values()])

    # 寻找累类似 <<1>> 的标记
    tagger = re.compile(r'<<.*?>>')
    tags = set()

    # 搜索 去重
    for line in lines:
        for match in tagger.finditer(line):
            tags.add(match.group(0))

    # 排序输出
    for tag in sorted(tags):
        print(tag)
예제 #2
0
def main():
    lang = 'zh'
    if len(sys.argv) == 2:
        lang = sys.argv[1]

    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')

    # load lua
    pregame_file = os.path.join(translation_path, 'en_pregame.lua')
    client_file = os.path.join(translation_path, 'en_client.lua')

    ui_mgr = UiMgr()
    ui_mgr.load_lua_file(pregame_file)
    ui_mgr.load_lua_file(client_file)
    print('read %d lines.' % len(ui_mgr.ui_lines))

    # save merged lines
    translate_file = os.path.join(translation_path, '%s_translate.txt' % lang)
    if os.path.exists(translate_file):
        choose = input('%s_translate.txt file exists, merge? [y/N]' % lang)
        choose = choose.lower().strip()
        if choose != '' and choose[0] == 'y':
            print('merging to translate file.')
            ui_mgr.apply_translate_from_txt_file(translate_file)
        else:
            print('skipped.')
            return

    with open(translate_file, 'wt', encoding='utf-8') as fp:
        fp.writelines(ui_mgr.get_txt_lines(replace=True))
        print('save translate file succeed.')
예제 #3
0
def main():
    lang = 'zh'

    if len(sys.argv) != 2:
        usage()
        sys.exit(2)

    xls_path = sys.argv[1]

    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')
    translate_file = os.path.join(translation_path, '%s_translate.txt' % lang)

    ui_mgr = UiMgr()

    # load lua
    pregame_src = os.path.join(translation_path, 'en_pregame.lua')
    ui_mgr.load_lua_file(pregame_src)

    client_src = os.path.join(translation_path, 'en_client.lua')
    ui_mgr.load_lua_file(client_src)

    # load translation
    data_from_xls = load_xls(xls_path)
    ui_mgr.apply_translate_from_xls(data_from_xls)
    ui_mgr.apply_translate_from_xls(data_from_xls)

    # save result
    txt_lines = ui_mgr.get_txt_lines(replace=True)
    with open(translate_file, 'wt', encoding='utf-8') as fp:
        fp.writelines(txt_lines)
        print('save translate file succeed.')
예제 #4
0
 def setUp(self):
     self.lua = [
         'SafeAddString(SI_ABILITYUPGRADELEVEL0, "None", 0)',
         '无',
         'SafeAddString(SI_ABILITYUPGRADELEVEL1, "Bronze", 0)\n',
         '青铜',
         'SafeAddString(SI_ABILITYUPGRADELEVEL2, "Silver", 0)\n',
         'SafeAddString(SI_ABILITYUPGRADELEVEL3, "Gold", 0)\n',
         '黄金\n',
     ]
     self.mgr = UiMgr()
     self.mgr.load_lua_lines(self.lua)
예제 #5
0
def main():
    lang = 'zh'
    if len(sys.argv) == 2:
        lang = sys.argv[1]

    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')

    # load lua
    pregame_file = os.path.join(translation_path, 'en_pregame.lua')
    client_file = os.path.join(translation_path, 'en_client.lua')

    ui_mgr = UiMgr()
    log.debug('loading lua file %s' % pregame_file)
    ui_mgr.load_lua_file(pregame_file)
    log.debug('loading lua file %s' % client_file)
    ui_mgr.load_lua_file(client_file)
    log.info('read %d lines.' % len(ui_mgr.ui_lines))

    # save merged lines
    translate_file = os.path.join(translation_path, '%s_translate.txt' % lang)
    if os.path.exists(translate_file):
        choose = input('%s_translate.txt file exists, merge? [y/N]' % lang)
        choose = choose.lower().strip()
        if choose != '' and choose[0] == 'y':
            log.info('merging to translate file.')
            ui_mgr.apply_translate_from_txt_file(translate_file)
        else:
            log.info('skipped.')
            return

    with open(translate_file, 'wt', encoding='utf-8') as fp:
        fp.writelines(ui_mgr.get_txt_lines(replace=True))
        log.info('save translate file succeed.')
예제 #6
0
def main():
    lang = 'zh'

    if len(sys.argv) != 2:
        usage()
        sys.exit(2)

    xls_path = sys.argv[1]

    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')
    translate_file = os.path.join(translation_path, '%s_translate.txt' % lang)

    ui_mgr = UiMgr()

    # load lua
    pregame_src = os.path.join(translation_path, 'en_pregame.lua')
    ui_mgr.load_lua_file(pregame_src)

    client_src = os.path.join(translation_path, 'en_client.lua')
    ui_mgr.load_lua_file(client_src)

    # load translation
    data_from_xls = load_xls(xls_path)
    ui_mgr.apply_translate_from_xls(data_from_xls, need_check=False)

    # save result
    txt_lines = ui_mgr.get_txt_lines(replace=True)
    with open(translate_file, 'wt', encoding='utf-8') as fp:
        fp.writelines(txt_lines)
        log.info('save translate file succeed.')
예제 #7
0
def main():
    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')

    lang_file = os.path.join(translation_path, 'lang/en.lang.csv')
    with open(lang_file, 'rt', encoding='utf-8') as fp:
        fp.readline()
        lines = [
            LangLine.from_csv_line(line).origin for line in fp.readlines()
        ]

    pregame_file = os.path.join(translation_path, 'en_pregame.lua')
    client_file = os.path.join(translation_path, 'en_client.lua')
    ui_mgr = UiMgr()
    ui_mgr.load_lua_file(pregame_file)
    ui_mgr.load_lua_file(client_file)
    lines.extend([ui_line.origin for ui_line in ui_mgr.ui_lines.values()])

    # 寻找累类似 <<1>> 的标记
    tagger = re.compile(r'<<.*?>>')
    tags = set()

    # 搜索 去重
    for line in lines:
        for match in tagger.finditer(line):
            tags.add(match.group(0))

    # 排序输出
    for tag in sorted(tags):
        print(tag)
예제 #8
0
def main():
    lang = 'zh'

    # getopt
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'l:')
    except getopt.GetoptError as e:
        log.error(e)
        sys.exit(2)
    for o, a in opts:
        if o == '-l':
            lang = a

    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')
    dest_path = translation_path

    ui_mgr = UiMgr()

    # load translation
    translate_file = os.path.join(translation_path, '%s_translate.txt' % lang)
    ui_mgr.load_lua_file(translate_file)
    ui_mgr.apply_translate_from_txt_file(
        translate_file)  # _translate.txt 中同时存了原文和译文

    rows = ui_mgr.get_rows()
    rows = [row for name, row in sorted(rows.items())]

    header = UiRow('名称') \
            .set_id('编号') \
            .set_origin('原文') \
            .set_translation('译文') \
            .set_translator('初翻人员') \
            .set_proofreader('校对') \
            .set_refiner('润色') \
            .set_comments('备注')
    rows[0:0] = [
        header,
    ]

    # save
    xls_file = os.path.join(dest_path, '%s_translate.xlsx' % lang)
    plain_rows = [row.to_list() for row in rows
                  ]  # list of [id, name, origin, translation, ...]
    save_xlsx(xls_file, plain_rows)
예제 #9
0
def main():
    lang = 'zh'

    # getopt
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'l:')
    except getopt.GetoptError as e:
        log.error(e)
        sys.exit(2)
    for o, a in opts:
        if o == '-l':
            lang = a

    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')
    dest_path = translation_path

    ui_mgr = UiMgr()

    # load translation
    translate_file = os.path.join(translation_path, '%s_translate.txt' % lang)
    ui_mgr.load_lua_file(translate_file)
    ui_mgr.apply_translate_from_txt_file(translate_file)      # _translate.txt 中同时存了原文和译文

    rows = ui_mgr.get_rows()
    rows = [row for name, row in sorted(rows.items())]

    header = UiRow('名称') \
            .set_id('编号') \
            .set_origin('原文') \
            .set_translation('译文') \
            .set_translator('初翻人员') \
            .set_proofreader('校对') \
            .set_refiner('润色') \
            .set_comments('备注')
    rows[0:0] = [header, ]

    # save
    xls_file = os.path.join(dest_path, '%s_translate.xlsx' % lang)
    plain_rows = [row.to_list() for row in rows]    # list of [id, name, origin, translation, ...]
    save_xlsx(xls_file, plain_rows)
예제 #10
0
def main():
    lang = 'zh'
    mode = 'both'   # origin, translation, both

    # getopt
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'l:m:h')
    except getopt.GetoptError as e:
        print(e)
        usage()
        sys.exit(2)
    for o, a in opts:
        if o == '-l':
            lang = a.lower()
        elif o == '-m':
            mode = a.lower()
            if mode not in ('origin', 'translation', 'both'):
                usage()
                sys.exit(2)
        elif o == '-h':
            usage()
            return

    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')
    dest_path = os.path.join(cd, '../AddOns/EsoUI/lang')

    # load header
    header_file = os.path.join(translation_path, 'str_header.txt')
    with open(header_file, 'rt', encoding='utf-8') as fp:
        header = fp.readlines()

    ui_mgr_pregame = UiMgr()
    ui_mgr_client = UiMgr()

    # load lua
    pregame_src = os.path.join(translation_path, 'en_pregame.lua')
    ui_mgr_pregame.load_lua_file(pregame_src)

    client_src = os.path.join(translation_path, 'en_client.lua')
    ui_mgr_client.load_lua_file(client_src)

    # load translation
    translate_file = os.path.join(translation_path, '%s_translate.txt' % lang)
    with open(translate_file, 'rt', encoding='utf-8') as fp:
        lines = fp.readlines()
        ui_mgr_pregame.apply_translate_from_txt_lines(lines)
        ui_mgr_client.apply_translate_from_txt_lines(lines)

    print('mode: %s' % mode)

    # save str
    pregame_dest = os.path.join(dest_path, '%s_pregame.str' % lang)
    pregame_lines = ui_mgr_pregame.get_str_lines(mode)
    print('save to %s.' % pregame_dest)
    with open(pregame_dest, 'wt', encoding='utf-8') as fp:
        fp.writelines(header)
        fp.writelines(pregame_lines)

    client_dest = os.path.join(dest_path, '%s_client.str' % lang)
    client_lines = ui_mgr_client.get_str_lines(mode)
    print('save to %s.' % client_dest)
    with open(client_dest, 'wt', encoding='utf-8') as fp:
        fp.writelines(header)
        fp.writelines(client_lines)

    # save en str (fix fonts)
    if lang != 'en':
        pregame_dest = os.path.join(dest_path, 'en_pregame.str')
        pregame_lines = ui_mgr_pregame.get_str_lines(mode)
        print('save to %s.' % pregame_dest)
        with open(pregame_dest, 'wt', encoding='utf-8') as fp:
            fp.writelines(header)
            # keep version info
            for line in pregame_lines:
                if line.startswith('[SI_VERSION] ='):
                    fp.write(line + '\n')

        client_dest = os.path.join(dest_path, 'en_client.str')
        client_lines = ui_mgr_client.get_str_lines(mode)
        print('save to %s.' % client_dest)
        with open(client_dest, 'wt', encoding='utf-8') as fp:
            fp.writelines(header)
            # keep version info
            for line in client_lines:
                if line.startswith('[SI_VERSION] ='):
                    fp.write(line + '\n')
예제 #11
0
class TestUiMgr(unittest.TestCase):
    def setUp(self):
        self.lua = [
            'SafeAddString(SI_ABILITYUPGRADELEVEL0, "None", 0)',
            '无',
            'SafeAddString(SI_ABILITYUPGRADELEVEL1, "Bronze", 0)\n',
            '青铜',
            'SafeAddString(SI_ABILITYUPGRADELEVEL2, "Silver", 0)\n',
            'SafeAddString(SI_ABILITYUPGRADELEVEL3, "Gold", 0)\n',
            '黄金\n',
        ]
        self.mgr = UiMgr()
        self.mgr.load_lua_lines(self.lua)

    def test_load_lua(self):
        self.assertEqual(4, len(self.mgr.ui_lines))
        self.assertEqual('None',
                         self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL0'].origin)
        self.assertEqual(
            '', self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL0'].translation)

    def test_apply_translation_txt(self):
        """测试从 .txt 文本文件中读入的翻译"""
        self.mgr.apply_translate_from_txt_lines(self.lua)

        self.assertEqual(4, len(self.mgr.ui_lines))
        self.assertEqual('None',
                         self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL0'].origin)
        self.assertEqual(
            '无', self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL0'].translation)
        self.assertEqual(
            '', self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL2'].translation)
        self.assertEqual(
            '黄金', self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL3'].translation)

    def test_apply_unknown_txt(self):
        """测试翻译 .txt 时的异常处理"""
        lua = [
            'SafeAddString(SI_ABILITYUPGRADELEVEL0, "Fake None", 0)',
            '无',
            'SafeAddString(SI_ABILITY_ACTION_CLEAR_SLOT, "Remove", 1)',
            '移除',
        ]
        self.mgr.load_lua_lines(self.lua)
        self.mgr.apply_translate_from_txt_lines(lua)

        self.assertEqual(
            '', self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL0'].translation)
        self.assertFalse(
            'SI_ABILITY_ACTION_CLEAR_SLOT' in self.mgr.ui_lines.keys())

    def test_apply_translation_xls(self):
        """测试应用从 xls 读入的数据"""
        data = [
            ['1', 'SI_ABILITYUPGRADELEVEL0', 'None', '无', '', '', '', ''],
            ['2', 'SI_ABILITYUPGRADELEVEL1', 'None', '无', '', '', '', ''],
            ['3', 'SI_ABILITYUPGRADELE__FAKE', 'None', '无', '', '', '', ''],
        ]
        self.mgr.apply_translate_from_xls(data)

        self.assertEqual('None',
                         self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL0'].origin)
        self.assertEqual(
            '无', self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL0'].translation)
        self.assertEqual(
            '', self.mgr.ui_lines['SI_ABILITYUPGRADELEVEL1'].translation)
        self.assertFalse(
            'SI_ABILITYUPGRADELE__FAKE' in self.mgr.ui_lines.keys())

    def test_get_rows(self):
        """测试生成 xls 数据的能力"""
        rows = self.mgr.get_rows()
        rows_list = [ui_row.to_list() for name, ui_row in sorted(rows.items())]
        expected_rows_list = [
            ['1', 'SI_ABILITYUPGRADELEVEL0', 'None', '', '', '', '', ''],
            ['2', 'SI_ABILITYUPGRADELEVEL1', 'Bronze', '', '', '', '', ''],
            ['3', 'SI_ABILITYUPGRADELEVEL2', 'Silver', '', '', '', '', ''],
            ['4', 'SI_ABILITYUPGRADELEVEL3', 'Gold', '', '', '', '', ''],
        ]
        self.assertEqual(expected_rows_list, rows_list)

        self.mgr.apply_one_translate('SI_ABILITYUPGRADELEVEL0', 'None', '无')
        expected_rows_list[0][3] = '无'
        rows = self.mgr.get_rows()
        rows_list = [ui_row.to_list() for name, ui_row in sorted(rows.items())]
        self.assertEqual(expected_rows_list, rows_list)

    def test_get_txt_lines(self):
        """测试生成 .txt 的能力"""
        lines = self.mgr.get_txt_lines()
        expected_lines = [
            'SafeAddString(SI_ABILITYUPGRADELEVEL0, "None", 0)\n',
            'SafeAddString(SI_ABILITYUPGRADELEVEL1, "Bronze", 0)\n',
            'SafeAddString(SI_ABILITYUPGRADELEVEL2, "Silver", 0)\n',
            'SafeAddString(SI_ABILITYUPGRADELEVEL3, "Gold", 0)\n',
        ]
        self.assertEqual(expected_lines, lines)

        self.mgr.apply_one_translate('SI_ABILITYUPGRADELEVEL0', 'None', '无')
        lines = self.mgr.get_txt_lines()
        expected_lines[1:1] = [
            '无\n',
        ]
        self.assertEqual(expected_lines, lines)

    def test_get_str_lines(self):
        """测试生成 .str 的能力"""
        lines = self.mgr.get_str_lines()
        expected_lines = [
            '[SI_ABILITYUPGRADELEVEL0] = "None"\n',
            '[SI_ABILITYUPGRADELEVEL1] = "Bronze"\n',
            '[SI_ABILITYUPGRADELEVEL2] = "Silver"\n',
            '[SI_ABILITYUPGRADELEVEL3] = "Gold"\n',
        ]
        self.assertEqual(expected_lines, lines)

        self.mgr.apply_one_translate('SI_ABILITYUPGRADELEVEL2', 'Silver', '白银')

        lines = self.mgr.get_str_lines(mode='origin')
        self.assertEqual(expected_lines, lines)
        lines = self.mgr.get_str_lines(mode='translation')
        expected_lines[2] = '[SI_ABILITYUPGRADELEVEL2] = "白银"\n'
        self.assertEqual(expected_lines, lines)
        lines = self.mgr.get_str_lines()
        expected_lines[2] = '[SI_ABILITYUPGRADELEVEL2] = "Silver 白银"\n'
        self.assertEqual(expected_lines, lines)
예제 #12
0
def main():
    lang = 'zh'
    mode = 'both'   # origin, translation, both

    # getopt
    try:
        opts, args = getopt.getopt(sys.argv[1:], 'l:m:h')
    except getopt.GetoptError as e:
        log.error(e)
        usage()
        sys.exit(2)
    for o, a in opts:
        if o == '-l':
            lang = a.lower()
        elif o == '-m':
            mode = a.lower()
            if mode not in ('origin', 'translation', 'both'):
                usage()
                sys.exit(2)
        elif o == '-h':
            usage()
            return

    cd = sys.path[0]
    translation_path = os.path.join(cd, '../translation')
    dest_path = os.path.join(cd, '../AddOns/EsoUI/lang')

    # load header
    header_file = os.path.join(translation_path, 'str_header.txt')
    with open(header_file, 'rt', encoding='utf-8') as fp:
        header = fp.readlines()

    ui_mgr_pregame = UiMgr()
    ui_mgr_client = UiMgr()

    # load lua
    pregame_src = os.path.join(translation_path, 'en_pregame.lua')
    ui_mgr_pregame.load_lua_file(pregame_src)

    client_src = os.path.join(translation_path, 'en_client.lua')
    ui_mgr_client.load_lua_file(client_src)

    # load translation
    translate_file = os.path.join(translation_path, '%s_translate.txt' % lang)
    with open(translate_file, 'rt', encoding='utf-8') as fp:
        lines = fp.readlines()
        ui_mgr_pregame.apply_translate_from_txt_lines(lines)
        ui_mgr_client.apply_translate_from_txt_lines(lines)

    log.info('mode: %s' % mode)

    # save str
    pregame_dest = os.path.join(dest_path, '%s_pregame.str' % lang)
    pregame_lines = ui_mgr_pregame.get_str_lines(mode)
    log.info('save to %s.' % pregame_dest)
    with open(pregame_dest, 'wt', encoding='utf-8') as fp:
        fp.writelines(header)
        fp.writelines(pregame_lines)

    client_dest = os.path.join(dest_path, '%s_client.str' % lang)
    client_lines = ui_mgr_client.get_str_lines(mode)
    log.info('save to %s.' % client_dest)
    with open(client_dest, 'wt', encoding='utf-8') as fp:
        fp.writelines(header)
        fp.writelines(client_lines)

    # save en str (fix fonts)
    if lang != 'en':
        pregame_dest = os.path.join(dest_path, 'en_pregame.str')
        pregame_lines = ui_mgr_pregame.get_str_lines(mode)
        log.info('save to %s.' % pregame_dest)
        with open(pregame_dest, 'wt', encoding='utf-8') as fp:
            fp.writelines(header)
            # keep version info
            for line in pregame_lines:
                if line.startswith('[SI_VERSION] ='):
                    fp.write(line + '\n')

        client_dest = os.path.join(dest_path, 'en_client.str')
        client_lines = ui_mgr_client.get_str_lines(mode)
        log.info('save to %s.' % client_dest)
        with open(client_dest, 'wt', encoding='utf-8') as fp:
            fp.writelines(header)
            # keep version info
            for line in client_lines:
                if line.startswith('[SI_VERSION] ='):
                    fp.write(line + '\n')