It is very important that your apps support multiple languages, if you want more people to use it.
While you may not always be able to translate to every language yourself, at least make sure that English is supported. Homey will use English when no translation is found.
- Store your translation strings in
/locales/languagecode.json
. Possible languages are:en
andnl
. Support for more languages will be added in the future. - Almost all strings are in the
/locales/
folder. The remaining are in your/app.json
.
/locales/en.json
{
"title": "Hello World",
"hello": "Hello, __name__",
"settings": {
"title": "My Title",
"intro": "This is an example page."
},
"pair": {
"press_button": "Press the `pair` button on your device."
}
}
Translating a string from your app
Just call Homey.__()
with the correct key to get the translation.
const Homey = require('homey');
console.log( Homey.__("title") ); // "Hello World"
Or with a variable:
const Homey = require('homey');
console.log( Homey.__("hello", { "name": "Dave" }) ); // "Hello, Dave"
Translating a string from the front-end
Within your settings and pairing page, you have access to all strings in a sub-object named settings
, respectively pair
. To access them in your HTML view:
/settings/index.html
<span data-i18n="settings.title">
<!-- "My Title" will be placed here -->
</span>
<p data-i18n="settings.intro">
<!-- "This is an example page." will be placed here -->
</p>
Accessing them from JavaScript:
/settings/index.html
function onHomeyReady( Homey ) {
alert( Homey.__("settings.title") ); // will alert "Settings page title"
}
The i18n object
To make development easier, some strings will still be in your app.json
, such as Driver names, Flow titles etc.
Just use the following syntax:
/app.json
"title": {
"en": "Hello World",
"nl": "Hallo wereld"
}
You can also input a single string, when translation isn't necessary:
/app.json
"title": "°C"
Always have at least an en
translation! This is what Homey will fall-back on when the user language can't be found.
Allowed languages
The following languages are currently allowed:
- English
en
- Dutch
nl
- German
de
- French
fr
- Italian
it
- Swedish
sv
- Norwegian
no