Trados Studio | 时刻的正则验证
如果 QA 工具运用得当,可将翻译中的低错降至最低程度。而正则表达式则是 QA 工具中的利器。现在就通过一个数字验证实例说明如何巧用正则表达式提高工作效率。
根据翻译风格指南,一天中的时刻如果是 12 小时制,则翻译须遵循以下规则:
12:00 a.m. -> 午夜 12:00
12:59 a.m. -> 午夜 12:59
1:00 a.m. -> 午夜 1:00
5:59 a.m. -> 午夜 5:59
6:00 a.m. -> 早上 6:00
8:59 a.m. -> 早上 8:59
9:00 a.m. -> 上午 9:00
11:59 a.m. -> 上午 11:59
12:00 p.m. -> 中午 12:00
12:59 p.m. -> 中午 12:59
1:00 p.m. -> 下午 1:00
6:59 p.m. -> 下午 6:59
7:00 p.m. -> 晚上 7:00
11:59 p.m. -> 晚上 11:59
其中小时和分钟之间的分隔符可能是单字节冒号或句号,am 可能有各种变体,如 a.m./a.m/am./AM/A.M/AM./aM/Am/aM./A.m…。pm 也是一样。
由于不同时刻,am/pm 需要翻译成不同译文,因此批量替换是不可能的。
如何验证最终译文完全遵循了风格指南呢?答案是正则验证。这么复杂的要求,只有编写一系列正则表达式,才能保证万无一失。
按照风格指南,编写的正则验证规则如下:
12(\.|:)(\d{1,2}) ?p(\.)?m(\.)? 中午 12:$2 GroupedSourceNotTarget
12(\.|:)(\d{1,2}) ?a(\.)?m(\.)? 午夜 12:$2 GroupedSourceNotTarget
\b(0?[1-5]{1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)? 午夜 $1:$3 GroupedSourceNotTarget
\b(0?[6-8]{1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)? 早上 $1:$3 GroupedSourceNotTarget
\b(0?(9|10|11){1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)? 上午 $1:$4 GroupedSourceNotTarget
\b(0?[1-6]{1})(\.|:)(\d{1,2}) ?p(\.)?m(\.)? 下午 $1:$3 GroupedSourceNotTarget
\b((0?[7-9]{1})|((10|11){1}))(\.|:)(\d{1,2}) ?p(\.)?m(\.)? 晚上 $1:$6 GroupedSourceNotTarget
将此文本保存为 .csv 格式,然后用转换工具将其转为 .sdlqasettings 格式,即可导入 Trados Studio。
转换后的 .sdlqasettings 格式内容如下:
<?xml version="1.0" encoding="utf-8"?>
<SettingsBundle>
<SettingsGroup Id="QAVerificationSettings">
<Setting Id="RegExRules">True</Setting>
<Setting Id="RegExRulesCount">7</Setting>
<Setting Id="RegExRules0">
<RegExRule
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/Sdl.Verification.QAChecker.RegEx">
<Description>Source ‹12(\.|:)(\d{1,2}) ?p(\.)?m(\.)?› matched but not target ‹中午 12:$2›</Description>
<IgnoreCase>true</IgnoreCase>
<RegExSource>12(\.|:)(\d{1,2}) ?p(\.)?m(\.)?</RegExSource>
<RegExTarget>中午 12:$2</RegExTarget>
<RuleCondition>GroupedSourceNotTarget</RuleCondition>
</RegExRule>
</Setting>
<Setting Id="RegExRules1">
<RegExRule
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/Sdl.Verification.QAChecker.RegEx">
<Description>Source ‹12(\.|:)(\d{1,2}) ?a(\.)?m(\.)?› matched but not target ‹午夜 12:$2›</Description>
<IgnoreCase>true</IgnoreCase>
<RegExSource>12(\.|:)(\d{1,2}) ?a(\.)?m(\.)?</RegExSource>
<RegExTarget>午夜 12:$2</RegExTarget>
<RuleCondition>GroupedSourceNotTarget</RuleCondition>
</RegExRule>
</Setting>
<Setting Id="RegExRules2">
<RegExRule
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/Sdl.Verification.QAChecker.RegEx">
<Description>Source ‹\b(0?[1-5]{1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)?› matched but not target ‹午夜 $1:$3›</Description>
<IgnoreCase>true</IgnoreCase>
<RegExSource>\b(0?[1-5]{1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)?</RegExSource>
<RegExTarget>午夜 $1:$3</RegExTarget>
<RuleCondition>GroupedSourceNotTarget</RuleCondition>
</RegExRule>
</Setting>
<Setting Id="RegExRules3">
<RegExRule
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/Sdl.Verification.QAChecker.RegEx">
<Description>Source ‹\b(0?[6-8]{1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)?› matched but not target ‹早上 $1:$3›</Description>
<IgnoreCase>true</IgnoreCase>
<RegExSource>\b(0?[6-8]{1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)?</RegExSource>
<RegExTarget>早上 $1:$3</RegExTarget>
<RuleCondition>GroupedSourceNotTarget</RuleCondition>
</RegExRule>
</Setting>
<Setting Id="RegExRules4">
<RegExRule
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/Sdl.Verification.QAChecker.RegEx">
<Description>Source ‹\b(0?(9|10|11){1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)?› matched but not target ‹上午 $1:$4›</Description>
<IgnoreCase>true</IgnoreCase>
<RegExSource>\b(0?(9|10|11){1})(\.|:)(\d{1,2}) ?a(\.)?m(\.)?</RegExSource>
<RegExTarget>上午 $1:$4</RegExTarget>
<RuleCondition>GroupedSourceNotTarget</RuleCondition>
</RegExRule>
</Setting>
<Setting Id="RegExRules5">
<RegExRule
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/Sdl.Verification.QAChecker.RegEx">
<Description>Source ‹\b(0?[1-6]{1})(\.|:)(\d{1,2}) ?p(\.)?m(\.)?› matched but not target ‹下午 $1:$3›</Description>
<IgnoreCase>true</IgnoreCase>
<RegExSource>\b(0?[1-6]{1})(\.|:)(\d{1,2}) ?p(\.)?m(\.)?</RegExSource>
<RegExTarget>下午 $1:$3</RegExTarget>
<RuleCondition>GroupedSourceNotTarget</RuleCondition>
</RegExRule>
</Setting>
<Setting Id="RegExRules6">
<RegExRule
xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://schemas.datacontract.org/2004/07/Sdl.Verification.QAChecker.RegEx">
<Description>Source ‹\b((0?[7-9]{1})|((10|11){1}))(\.|:)(\d{1,2}) ?p(\.)?m(\.)?› matched but not target ‹晚上 $1:$6›</Description>
<IgnoreCase>true</IgnoreCase>
<RegExSource>\b((0?[7-9]{1})|((10|11){1}))(\.|:)(\d{1,2}) ?p(\.)?m(\.)?</RegExSource>
<RegExTarget>晚上 $1:$6</RegExTarget>
<RuleCondition>GroupedSourceNotTarget</RuleCondition>
</RegExRule>
</Setting>
</SettingsGroup>
</SettingsBundle>
导入 Trados Studio 后,测试一下,效果如下: