SDL Trados 2021 Bilingual 双语文件类型处理

news/2024/7/21 5:59:46 标签: SDL Trados 2021, Bilingual File, 双语文件, Excel, excel

Bilingual 双语文件类型

Bilingual 双语文件类型指的是在一个文件中包含两种文字语言,并且两种文字语言有规律可循

例1

en-US = "Hello World";
zh-CN = "你好世界";

en-US = "What's the weather like today?";
zh-CN = "今天天气怎么样?"

例2

<tu>
<source>Hello World</source>
<target>你好世界</target>
</tu>
<tu>
<source>What's the weather like today?</source>
<target>今天天气怎么样?</target>
</tu>

例3

'国内' => 'Domestic',
'海外' => 'Overseas',
'当前操作环境' => 'Current Environment',
'开发环境' => 'Development ',

他们的共同点:

  1. 有规律可循
  2. 有的单元有完整译文,因此疑问需要处理为审校;有的单元没有译文,要处理为翻译

按照SDL Trados官方的处理建议是使用BilingualFileTypeAPI 编写自定义插件以支持文件类型
见 SDL File Type Support 3.0
http://producthelp.sdl.com/SDK/FileTypeSupport/3.0/html/671d5ad6-8de2-40a5-adc9-4406c146cf73.htm
建立一个Sniff类并继承 INativeFileSniffer接口
建立Paser类继承AbstractBilingualFileTypeComponent, IBilingualParser, INativeContentCycleAware, ISettingsAware接口
并且建立一个Writer类继承AbstractBilingualFileTypeComponent, IBilingualWriter, INativeOutputSettingsAware接口
并且还要处理TAG,Comments,ConfirmationLevel等细节

这看起来似乎有些复杂了,如果每次遇到双语文件类型都这么开发一次要花费的时间可观啊
有没有简单的方法呢,我们来找一下:
SDL Trados 2021 的解析器中有这样一个Excel解析器,Bilingual Excel
在这里插入图片描述并且这个解析器定义了完善的处理规则,排除规则,备注规则,已存在内容的处理规则以及嵌入式规则
在这里插入图片描述这基本上就是我们要的,那么我们就尝试使用这个Bilingual Excel处理器解析任意Bilingual File,要进行这样的操作我们就需要:

  1. Bilingual File转换为Bilingual Excel 然后进行翻译
  2. 将翻译后的Bilingual Excel中的翻译好的内容写回Bilingual File

以上面的例三为例,来看一下,首先Bilingual File转换为Bilingual Excel

//现根据文档规则定义一个结构相关的正则表达式
public Regex RXRule = new Regex(@"^(\s+)?'(.*?)'(\s+)?=>(\s+)?'(.*?)',.*?$",RegexOptions.Compiled);

//转换方法,我这里使用SimpleOOXML一个简单的OpenXML扩展来处理Excel
public void ReadFile(string infile, string outfile)
{  
    using (MemoryStream stream = SpreadsheetReader.Create())
    {
        using (SpreadsheetDocument doc = SpreadsheetDocument.Open(stream, true))
        {
            var sheet = SpreadsheetReader.GetWorksheetPartByName(doc, "Sheet1");
            var writer = new WorksheetWriter(doc, sheet);

            int counter = 0;
            using (StreamReader sr = new StreamReader(infile, Encoding.UTF8, true))
            {
                string line = "";
                while (sr.Peek() > 0)
                {
                    line = sr.ReadLine();
                    string key, value;
                    if (RXRule.IsMatch(line))
                    {
                        counter++;

                        Match m = RXRule.Match(line);
                        key = m.Groups[2].Value;
                        value = m.Groups[5].Value;

                        writer.PasteSharedText("A" + counter, counter.ToString());
                        writer.PasteSharedText("B" + counter, key);

                        if(key !=value)
                            writer.PasteSharedText("C" + counter, value);
                    }
                }
            }
            writer.Save();
            if (File.Exists(outfile))
                File.Delete(outfile);
            SpreadsheetWriter.StreamToFile(outfile, stream);
        }
    }
    
}

用一段很简单的代码将文件转为下列表格形式
在这里插入图片描述之后还要有将翻译后内容写回Bilingual File的功能

//现根据文档规则定义一个结构相关的正则表达式
//我们采用正则表达式替换的方式将译文写回
public Regex RXRule = new Regex(@"^(\s+)?'(.*?)'(\s+)?=>(\s+)?'(.*?)',(.*?)$", RegexOptions.Compiled);
string r1 = @"$1'$2'$3=>$4'";
string r2 = @"',$6";

//转换方法,我这里使用SimpleOOXML一个简单的OpenXML扩展来处理Excel
public void ReadFile(string infile, string outfile)
{
    Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();

    using (SpreadsheetDocument doc = SpreadsheetDocument.Open(infile, false))
    {
        WorkbookPart wbPart = doc.WorkbookPart;
        Sheet sheet = wbPart.Workbook.Descendants<Sheet>().FirstOrDefault(c => c.Name == "Sheet1");
        WorksheetPart wsPart = (WorksheetPart)wbPart.GetPartById(sheet.Id);
        if (sheet != null)
        {
            SharedStringTable stringTable = doc.WorkbookPart.SharedStringTablePart.SharedStringTable;

            IEnumerable<Row> rows = wsPart.Worksheet.Descendants<Row>();
            //bool IsFirstRow = true;
            foreach (Row row in rows)
            {
                Cell dDell = row.Descendants<Cell>().First<Cell>();
                if (!GetValue(dDell, stringTable).Equals("N/A"))
                {
                    IEnumerator<OpenXmlElement> o = row.GetEnumerator();
                    o.MoveNext();
                    o.MoveNext();
                    string s = GetValue((Cell)o.Current, stringTable);
                    o.MoveNext();
                    string t = GetValue((Cell)o.Current, stringTable);

                    KeyValuePair<string, string> N = new KeyValuePair<string, string>(s, t);
                    if (!keyValuePairs.Contains(N))
                        keyValuePairs.Add(s,t);
                }
            }
        }
    }
//先把Excel读到 Dictionary<string, string> keyValuePairs 里面
//然后一边读源文件一边替换并写出翻译后的文件
    using (StreamReader sr = new StreamReader(Path.ChangeExtension(infile,".php"), Encoding.UTF8, true))
    {
        using (StreamWriter sw = new StreamWriter(outfile, false, new UTF8Encoding(false)))
        {
            string line = "";
            
            while (sr.Peek() > 0)
            {
                line = sr.ReadLine();
                string key, value;

                if (RXRule.IsMatch(line))
                {
                    Match m = RXRule.Match(line);
                    key = m.Groups[2].Value;
                    value = m.Groups[5].Value;

                    string trans = "";
                    if (keyValuePairs.TryGetValue(key, out trans))
                    {
                        line = RXRule.Replace(line, r1 + trans + r2);
                    }
                    sw.WriteLine(line);
                }
                else
                {
                    sw.WriteLine(line);
                }
            }

            sw.Flush();
        }                    
    }
}

至此就完成了,是不是很容易了呢


http://www.niftyadmin.cn/n/1735162.html

相关文章

SDL Trados 2019 和 SDL Trados 2021 最新版本的下载地址 (2021年七月更新)

SDL Trados 2019 和 SDL Trados 2021 最新版本的下载地址 SDL Trados 2019 CU 8 fix GS and Language Cloud 相关网络问题&#xff0c;正常使用没有必要更新 下载地址: https://update.sdl.com/updates/update1/studio15/live/SDLTradosStudio2019_SR2_15.2.8.3007.exe htt…

认知空间是什么意思_赵磊:一名合格引导师的自我认知

记得两三年前&#xff0c;当和别人提起引导师的时候&#xff0c;很多人带着莫名的疑惑&#xff1a;引导师是干什么的&#xff1f;引导是什么&#xff1f;引导术是什么&#xff1f;现在&#xff0c;越来越多人开始关注引导、学习引导技术&#xff0c;甚至想成为专职的引导师。工…

很慢怎么办_为什么我的Power BI Matrix或Table Visual很慢(上)

​你常常已创建具有许多可视化和计算的Power BI报告&#xff0c;但速度很慢&#xff01;最慢的部分是报告页面&#xff0c;其中包含矩阵或表格可视化&#xff01;视觉为何如此缓慢&#xff1f;这是Power BI中的控件问题吗&#xff1f;或Power BI问题呢&#xff1f;或者与建模和…

php开发app靠谱吗_教你如何选择一家靠谱的APP开发公司

移动互联网的发展催生了APP开发市场的火爆&#xff0c;不少的企业纷纷着手APP应用制作&#xff0c;但百分之九十以上的企业自身根本不具备开发APP应用的能力&#xff0c;只能选择外包公司来制作。但是APP开发市场鱼龙混杂&#xff0c;其中的规模有大有小&#xff0c;有个人有团…

showexport 属性不管用_闫妮:不管多大岁数,对爱情都愿意120%付出

闫妮接受媒体采访时称&#xff0c;电视剧《装台》中自己饰演的蔡素芬不管遇到多大挫折都拥有爱的能力&#xff0c;这点跟她一样。“不管多大岁数&#xff0c;提起爱情都愿意120%去付出&#xff0c;哪怕得不到回报也不后悔。”闫妮剧照《装台》里的蔡素芬&#xff0c;对丈夫刁顺…

岳阳机器人餐厅在哪_小米AIOT爆品,2500Pa大吸力,米家扫拖机器人1C教你一扫光...

用智能家居&#xff0c;我们既能享受科技生活的便捷&#xff0c;同时有更多的时间去学习、工作、陪伴家人。智能家居的核心就是减负&#xff0c;而第一件事就是干掉家务&#xff0c;最近入手了“米家扫拖机器人1C”&#xff1b;它有2500pa超大吸力&#xff0c;杂物一扫光&#…

3维线程格 gpu_《多核与GPU编程:工具、方法及实践》----3.2 线程-阿里云开发者社区...

本节书摘来自华章出版社《多核与GPU编程&#xff1a;工具、方法及实践》一书中的第3章&#xff0c;第3.2节&#xff0c; 作 者 Multicore and GPU Programming: An Integrated Approach&#xff3b;阿联酋&#xff3d;杰拉西莫斯巴拉斯(Gerassimos Barlas) 著&#xff0c;张云泉…

字幕 Subtitle

字幕&#xff08;subtitles of motion picture&#xff09;是指以文字形式显示电视、电影、舞台作品中的对话等非影像内容&#xff0c;也泛指影视作品后期加工的文字。在电影银幕或电视机荧光屏下方出现的解说文字以及种种文字&#xff0c;如影片的片名、演职员表、唱词、对白、…