JavaScript Localization

One of the best ways for your applications to reach a larger audience is to cater for multiple languages. This can often prove to be a daunting task, but the internationalization and localization features in CakePHP make it much easier.

 To read more about the general approach, please read the CakePHP documentation on Internationalization & Localization.

These features are great, but miss one important part: translating of JavaScript strings. Bancha provides you these frontend and backend tools for translation management.

Localizing in the Frontend

Bancha provides already build in support for localizing your frontend, simply use Bancha.Localizer:

Bancha.Localizer.setCurrentLanguage(lang); // To change the language
var localizedString = Bancha.t('And then translate strings.');

You can find an example here: Bancha Localization Example

Translation Management

Bancha uses (like CakePHP) POT files to define translations. The following cake shell command will collect all translatable JavaScript strings and generate the catalog app/Locale/bancha.pot from these:

./Console/cake bancha.jsi18n

Create your translation from these, like you would with any CakePHP strings and save them as e.g. for german app/Locale/deu/LC_MESSAGES/bancha.po

Bancha will load the necessary translations in the frontend and translates the strings.


Add a comment