Localization
You can override the user’s default locale to utilize localization for a specific language.
See Localization in our message content documentation for more details.
Overriding locale
Airship uses the user’s LocaleThe combination of a language and country. A user’s locale is determined by their device settings. for various locale-sensitive tasks, including selecting the language for messages and reporting for analytics. The SDK can override the locale so that Airship uses a different locale than the browser’s current locale.
In the Web SDK, a locale can be set before or after creating a channel. If set, it overrides the browser’s locale information. See the Web SDK reference for the full Locale Manager.
const sdk = await UA
await sdk.locale.set({language: 'fr'})
const sdk = await UA
await sdk.locale.set({country: 'FR'})
const sdk = await UA
await sdk.locale.clear()
const sdk = await UA
// replace just the language
await sdk.locale.set({language :'fr'})
// replace just the country
await sdk.locale.set({country :'FR'})
// replace both
await sdk.locale.set({country :'fr', language :'fr'})
Overrides can be reset by passing null
as the value for either the country
or language
key to set()
.
const sdk = await UA
await sdk.locale.set({country: null, language: 'fr'})
You may also retrieve the current resolved locale; this will coalesce the values provided by the browser with the current override values that you have set:
const sdk = await UA
const {language, country} = await sdk.locale.get()
Not all browser and OS combinations will provide a country, so the value of country
may be null
.
Categories