google translator toolkit - how to exclude portions of the text from being processed

一个人想着一个人 提交于 2020-06-23 08:28:08

问题


Does anybody know whether there is a possiblity to exclude portions of a text from being processed by the google translator toolkit?

A great advantage of this tool is that it suggests the translations of sentences which have already been translated in another context. However, if any additional footnote and/or remark has been added to the text, it won't be recognized as a match. I am looking for a possibility to enclose such text in "brackets" within which it will be ignored.

For example, the following two strings should be recognized as identical:

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

and be translated i.e. into German as:

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

If neccessary I could number such insertions and place their content into additional paragraphs like:

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

thanks a lot in advance, Marcel


回答1:


Quoting from the Google Translate FAQ ...

How do I tell Cloud Translation API to NOT translate something?

You can use the following HTML tags:

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

This functionality requires the source text to be submitted in HTML.

If it's "not working for you" a likely reason is that you requested TEXT translation not HTML translation. If you only want TEXT translation then wrapper your plan text in HTML tags (with <span> tags as above) and then unwrap after translation.




回答2:


Add a span tag with a class of 'skiptranslate' to the bits that you do not want to be translated, like this:

"This is <span class="skiptranslate">this text will be ignored</span> one continuous sentence."




回答3:


The "skiptranslate" class didn't work for me in the po files I submitted to gtt. Gtt continued to translate everything. I noticed that gtt does not translate anything inside an href attribute, so what I did was to pre-process my .po file (using a "copy" grunt task) by changing {{my_expr}} type strings to <a href='{{my_expr}}/> strings, then changing them back to {{my_expr}} after the gtt translation (using another "copy" grunt task).

I'm not sure how this affects the semantics of the translation, but at least the resulting translation doesn't break my templating code.

Here is my grunt copy task config showing the regular expressions I used:

    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');
          }
        }
      }
    }


来源:https://stackoverflow.com/questions/33942733/google-translator-toolkit-how-to-exclude-portions-of-the-text-from-being-proce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!