For example if i would like to define text messages in multiple languages:
const AVAILABLE_LANGUAGES = ["en", "fr"];
const CONFIRM_BUTTON_TEXT = { "en": "Confirm", "fr": "Confirm in french"};
Then somewhere in a component template be able to use them like:
<button>@{global.CONFIRM_BUTTON_TEXT.en}</button>
or in a component script or controller like:
var default_language = global.AVAILABLE_LANGUAGES[0];
- where should I define those constants for best practice
- how can I access them in components with javascript
- how can I access them in html templates
- how can I access them in controllers
I recommend to use Total.js Localization with
@(Localization markup), example below. Total.js Localization is the answer for your questions.and usage in JS code on server-side:
Read more: https://docs.totaljs.com/latest/en.html#pages~Localization
BTW: If you want to use localization on client-side in JS code, then you can be inspired with
j-Resourcecomponent: https://componentator.com/components/j-resource/