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

前端 未结 3 2107
旧时难觅i
旧时难觅i 2021-01-22 09:01

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 t

相关标签:
3条回答
  • 2021-01-22 09:23

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

    0 讨论(0)
  • 2021-01-22 09:38

    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.

    0 讨论(0)
  • 2021-01-22 09:39

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

    0 讨论(0)
提交回复
热议问题