3

有谁知道是否有可能将部分文本排除在谷歌翻译工具包的处理范围之外?

这个工具的一个很大的优点是它建议翻译已经在另一个上下文中翻译的句子。但是,如果文本中添加了任何其他脚注和/或备注,则不会被识别为匹配项。我正在寻找一种将此类文本括在“括号”中的可能性,在该括号中它将被忽略。

例如,以下两个字符串应被识别为相同:

"This is one continuous sentence."
"This is {this text will be ignored}one continuous sentence."

并被翻译成德语:

"Dies ist ein zusammenhängender Satz."
"Dies is {this text will be ignored}ein zusammenhängender Satz."

如有必要,我可以对此类插入进行编号并将其内容放入其他段落中,例如:

"This is one continuous sentence."
"This is {1}one continuous sentence."
"{1 this text will be ignored}

非常感谢,马塞尔

4

3 回答 3

1

引用谷歌翻译常见问题...

如何告诉 Cloud Translation API 不翻译某些内容?

您可以使用以下 HTML 标记:

<span translate="no"> </span>
<span class="notranslate"> </span>

此功能需要以 HTML 格式提交源文本。

如果它“不适合您”,一个可能的原因是您要求 TEXT 翻译而不是 HTML 翻译。如果您只想要 TEXT 翻译,则将您的计划文本包装在 HTML 标记中(使用<span>上述标记),然后在翻译后展开。

于 2019-08-24T01:50:03.413 回答
0

在我提交给 gtt 的 po 文件中,“skiptranslate”类对我不起作用。Gtt 继续翻译一切。我注意到 gtt 不会翻译 href 属性中的任何内容,所以我所做的是通过将{{my_expr}}类型字符串更改为字符串来预处理我的 .po 文件(使用“复制”grunt 任务) <a href='{{my_expr}}/>,然后将它们改回{{my_expr}}gtt 之后翻译(使用另一个“复制”咕噜任务)。

我不确定这如何影响翻译的语义,但至少生成的翻译不会破坏我的模板代码。

这是我的 grunt 复制任务配置,显示了我使用的正则表达式:

    copy: {
   
      fixupPoFileForTranslation: {
        src: [],   // Fill in src and dest!
        dest: '',  
        options : {
          process: function (content, srcpath) {

            return content.replace(/"Go page"/g, '"Go"')
            // Change handlebars {{<name>}} to <a ref='<name>'/> to stop
            // machine translation from translating them.
            return content.replace(/(\{\{[a-zA-Z_\$].*?\}\})/g, '<a href=\'$1\'/>')
              // Same thing for our js .format {0}, {1}, ...
                          .replace(/(\{\d*?\})/g, '<a href=\'$1\'/>');
          }
        }
      },

      fixupPoFileForMerge: {
        src: [],
        dest: '',
        options : {
          process: function (content, srcpath) {

            // Restore <a href=... back to {{<name>}}
            return content..replace(/<a href='(\{\{[a-zA-Z_\$].*?\}\})'(\/>|)/gi, '$1')
            // Same thing for {0} constructs
                          .replace(/<a href=' *(\{.\d?\})('\/>|)/gi, '$1');
          }
        }
      }
    }

于 2016-02-25T02:27:51.830 回答
0

将具有“skiptranslate”类的 span 标签添加到您不想翻译的位,如下所示:

“这是<span class="skiptranslate">this text will be ignored</span>一个连续的句子。”

于 2016-02-12T15:10:00.350 回答