Is there any mechanism in yii framework to translate messages in javascript source files.
For example with:
yiic message config-message.php
I can generate translation .php files for all Yii::t().
Is it possible to generate .js files with the same mechanism. Currently I'm including to my javascript json data with table returned by translation file.
Internationalization (I18N) is the process of designing and preparing software products (apps) to support multiple locales, languages, and regions. By internationalizing a codebase, developers and businesses can expand their user base and access a wider audience.
A Locale object represents a specific geographical, political, or cultural region. An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user.
Polyglot. js is a tiny I18n helper library written in JavaScript, made to work both in the browser and in CommonJS environments (Node). It provides a simple solution for interpolation and pluralization, based off of Airbnb's experience adding I18n functionality to its Backbone. js and Node apps.
An alternate solution would be to make Yii include translated messages in the DOM, that will be later accessed by your JS code, so:
I've created an extension that should handle this:
http://www.yiiframework.com/extension/jstrans/
It's a really problem. Multi languages sites is always problem. YII solve the problem for php code. But js code problem still on place.
I do not very elegant solution but it's works. Create controller/component and generate js code with localization on the fly using t().
/js/get/?file=some-js-file in layout:
Of course, every JS need to be rewrite. If use small pieces of code (cs()->RegisterScript) I use t() as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With