dev-master
9999999-dev https://github.com/wvdongen/CakePHP-I18nJsTranslate JavaScript strings like Drupal 8.
MIT
The Requires
- php >=5.4
cakephp i18n translate i18njs
Translate JavaScript strings like Drupal 8.
A CakePHP 2.x plugin to translate JavaScript strings. The JavaScript functions and methods to fetch the translation strings are taken from Drupal 8., (*1)
APP/Plugin/I18nJs
CakePlugin::load('I18nJs')
or CakePlugin::loadAll()
in your bootstrap$this->Html->script('/i18n_js/js/18n_js')
$this->Html->script('/js/Locale/i18n_js.' . $this->Session->read('Config.language'))
Translate strings to the page language or a given language., (*2)
Examples:, (*3)
I18nJs.t('This string needs transalation'); I18nJs.t('Welcome @name', {'@name': 'Wouter'});
Format a string containing a count of items., (*4)
Examples:, (*5)
Drupal.formatPlural(count, '@name has 1 site.', '@name has @count sites.', {'@name': personName}); Drupal.formatPlural(count, '1 comment', '@count comments');
Console/cake I18nJs.i18n_js extract_js
This will parse all the javascript translation functions from your .js and .ctp files. This will create the file App/Locale/i18n_js.pot
., (*6)
Make sure your translations are located in App/Locale/<language>/LC_MESSAGES/i18n_js.po
., (*7)
Console/cake I18nJs.i18n_js create_js
This will create JavaScript file(s) as App/webroot/js/Locale/i18n_js.<language>.js
., (*8)
This fill should be added to your HTML. Add for example the following to your default.ctp
file:, (*9)
echo $this->Html->script('/js/Locale/i18n_js.' . $this->Session->read('Config.language'));
Translate JavaScript strings like Drupal 8.
MIT
cakephp i18n translate i18njs