eZ Community » Forums » Translation » A new language or locale ? » Translate a message from Javascript
expandshrink

Translate a message from Javascript

Translate a message from Javascript

Thursday 26 March 2015 10:24:51 am - 1 reply

Hey

I have a Javascript file and in there is a message for a cookie.

How can i translate this one when i switch from one to another language?

Friday 27 March 2015 9:35:40 am

Hello Lena,

Welcome again to the eZ Community!

In short the problem is that by default javascript files are basically separate from all aspects of eZ Publish unless you construct solutions within your custom javascript (like the above described solution) which call to eZ Publish to fetch required content / information / etc.

You could use ezjscore to create a solution to call via javascript on demand to translate javascript based strings using eZ Publish PHP API and return the translated string (or strings, plural).

Another (better) idea I had while typing this reply was to use design.ini settings customized per siteaccess to load a separate javascript file containing your string translations in javascript variables and only load the separate javascript file containing your string translations in the needed language for that specific siteaccess. This would be the simplest solution to implement.

Can you share more specific details about your need to translate javascript based strings and perhaps we can come up with some better suggestions?

I hope this helps!

Cheers,
Heath

expandshrink

You must be logged in to post messages in this topic!

Proudly Developed with from