google-translate-php icon indicating copy to clipboard operation
google-translate-php copied to clipboard

Translate everything except dynamic variables/attributes?

Open 2K11CS12 opened this issue 4 years ago • 1 comments

Hi,

How can I translate string having dynamic variables/attributes, something like below?

Here's your {{ value }} gift card for {{ shop }}!

Just want to translate text which is not wrapped in curly braces.

any help/idea will be helpful!

Thanks

2K11CS12 avatar Apr 28 '21 12:04 2K11CS12

According to Google instructions, setting class="notranslate" prevents Google translation. So, for your question the only way is using this html class method.

Here's your <span class="notranslate">{{ value }}l</span> gift card for <span class="notranslate">{{ shop}}l</span>!

ShpendBerisha avatar May 04 '21 22:05 ShpendBerisha

I don't think it is possible through translating strings. The idea suggested by @ShpendBerisha won't work because Google will still translate text inside tags because it won't treat it as a webpage (The "notranslate" is used for translating webpages by link).

The only way I found is wrapping text inside < and > like this:

Here's your <{{value}}> gift card for <{{shop}}> !

Note that you should remove spaces between braces words.

P.S. I don't recommend relying on this because it might stop working at any time.

Stichoza avatar Nov 28 '22 20:11 Stichoza