【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文件路径')

结果

相关推荐
ScilogyHunter2 小时前
[14] TMS570LC4357_VIM向量中断:128 通道、双 VIM 与硬件向量分发
单片机·编辑器·vim·excel·hercules·tms570
wuyk55520 小时前
Python办公自动化-第02讲-Excel文件认知与四大库选型
开发语言·python·excel
用户298698530141 天前
React 前端实现 Excel 与 HTML 双向转换:基于 WebAssembly 的浏览器端方案
javascript·html·excel
用户0332126663672 天前
使用 Python 轻松移除 Excel 文档中的重复行
python·excel
AI英德西牛仔2 天前
智谱清言导出word指令失效?PC端深度用户正在用“AI导出鸭”重构内容归档流
人工智能·重构·word·excel·deepseek·ai导出鸭
用户0332126663673 天前
使用 Python 删除 Excel 中的空白行或空白列
python·excel
wuyk5556 天前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel
黎羽_7 天前
Excel 插图在手机端不显示/错位:完整排查手册
excel·openpyxl·移动端·办公文档
用户298698530148 天前
React 前端实现 Excel 与 CSV 互转:基于 WebAssembly 的浏览器端方案
javascript·react.js·excel
仓库日记9 天前
Excel进销存何时该换?用3项检查判断是否需要软件
经验分享·excel·进销存·开单软件