Skylight Docs
Search…
String localization
This is a recipe showing how to localize strings based on the user's context.
skylight-export-Recipe_ String Localization-01.zip
3KB
Binary
String Localization Recipe Application Bundle
Example of application responding to user locale updates

What does this recipe include?

The application data for this recipe stores the translated string values:
1
{
2
"defaultLocale": "en",
3
"strings": {
4
"welcome": {
5
"en": "Welcome!",
6
"es": "Bienvenidas!",
7
"de": "Willkommen!",
8
"fr": "Bienvenue!",
9
"pt": "Bem vindo!",
10
"it": "Benvenuta!",
11
"zh": "欢迎!",
12
"ja": "ようこそ!"
13
}
14
}
15
}
Copied!
If the user's locale is set to "Domain Default", skylight.user.localewill return an empty string. There is currently no way to retrieve the domain's default locale, so we store the default locale in application data (which will need to be updated whenever the domain default is updated).
The root view contains a single card that has its text bound to:
1
{{ application.data.strings.welcome[user.locale ? user.locale : application.data.defaultLocale] }}
Copied!
This databinding accesses the appropriate welcome string from application data using the user's locale. If the user's locale is an empty string, we use the default locale specified by the application data.
This card also has an onSelect action that runs the following script when selected:
1
const applicationStrings = skylight.application.data.strings
2
const welcomeStrings = applicationStrings.welcome
3
4
// If user.locale is an empty string, that means that it is currently set to the domain default.
5
// In the future, the domain default locale will be accessible through the scripting API; for now
6
// we resort to storing it in a value in application data
7
const locale = skylight.user.locale ? skylight.user.locale : skylight.application.data.defaultLocale
8
const localizedWelcome = welcomeStrings[locale]
9
10
skylight.showNotification({
11
body: localizedWelcome
12
})
Copied!
This script uses a logic similar to the text databinding to show a localized notification.
For more details on localization in Skylight, see https://docs.upskill.io/admin/localization
For more details on retrieving the user's locale using the scripting API, see https://docs.upskill.io/development/reference/scripting-api#user-locale
Last modified 5mo ago