【问题标题】:google translator toolkit - how to exclude portions of the text from being processed谷歌翻译工具包 - 如何排除部分文本正在处理
【发布时间】:2020-05-22 04:09:58
【问题描述】:

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

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

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

"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}

提前非常感谢, 马塞尔

【问题讨论】:

    标签: translation google-translate machine-translation


    【解决方案1】:

    引用Google Translate FAQ ...

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

    您可以使用以下 HTML 标签:

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

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

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

    【讨论】:

    【解决方案2】:

    为不想翻译的位添加一个带有“skiptranslate”类的span标签,如下所示:

    “这是&lt;span class="skiptranslate"&gt;this text will be ignored&lt;/span&gt;一个连续的句子。”

    【讨论】:

    • 我认为是notranslate 而不是skiptranslate
    【解决方案3】:

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

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

    这是我的 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');
              }
            }
          }
        }

    【讨论】:

    • 我认为是notranslate 而不是skiptranslate
    猜你喜欢
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-15
    • 2011-10-05
    • 1970-01-01
    • 2012-01-03
    • 2013-01-29
    相关资源
    最近更新 更多