Stichoza / google-translate-php

🔤 Free Google Translate API PHP Package. Translates totally free of charge.
MIT License
1.79k stars 380 forks source link

Translate everything except dynamic variables/attributes? #167

Closed 2K11CS12 closed 1 year ago

2K11CS12 commented 3 years ago

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

ShpendBerisha commented 3 years ago

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>!

Stichoza commented 1 year ago

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.