【SDL Trados Studio】sdltm格式转excel

思路

1.sdltm转tmx(SDL Trados Studio)

2.tmx转excel(代码/Xbench/Maxprograms/Localazy)

步骤

1.利用SDL Trados Studio打开sdltm文件

2.将选择要导出的翻译库,右键导出

3.查看tmx文件,发现tmx文件符合xml文件格式

4.利用python将tmx文件转为excel文件

代码

python 复制代码
import pandas as pd
import xml.etree.ElementTree as ET
def get_text_for_tag(root):
    texts = []
    for element in root.iter():
        if element.text:
            texts.append(element.text)
        if element.tail and element.tail != "\n      ":
            texts.append(element.tail)
    return ''.join(texts)
def tmx_to_excel(tmx_file, excel_file):
    tree = ET.parse(tmx_file)
    root = tree.getroot()
    # 初始化数据列表
    data = []
    # 遍历TMX文件中的每个tu(翻译单元)
    for tu in root.findall('.//tu'):
        seglist = tu.findall("tuv/seg")
        source_text = get_text_for_tag(seglist[0])
        target_text = get_text_for_tag(seglist[1])
        data.append([source_text, target_text])
    # 创建DataFrame
    df = pd.DataFrame(data, columns=['Source', 'Target'])
    # 导出为Excel文件
    df.to_excel(excel_file, index=False)
# 使用示例
tmx_to_excel(r'tmx文件路径', r'xlsx文件路径')

结果

相关推荐
UR的出不克12 小时前
使用 Python 爬取 Bilibili 弹幕数据并导出 Excel
java·python·excel
wtsolutions12 小时前
Understanding Excel Data Formats - What Excel to JSON Supports
ui·json·excel
ぁず13 小时前
excel想生成一列随机数并删除公式保留值
excel
wtsolutions16 小时前
Real-World Use Cases - How Organizations Use Excel to JSON
json·github·excel
一只小H呀の16 小时前
pandas处理excel数据
excel·pandas
wregjru16 小时前
【操作系统】3.开发工具
excel
wtsolutions19 小时前
MCP Service Integration - Excel to JSON for AI and Automation
人工智能·json·excel
wtsolutions1 天前
JSON to Excel Add-in - Seamless Integration Within Excel
json·excel
wtsolutions1 天前
Getting Started with JSON to Excel Web App - Convert in Seconds
json·excel·web app
wtsolutions1 天前
Using the JSON to Excel API - Programmatic Access for Developers
json·excel