Locale

Configure locale behavior and override the default locale that Airship uses.

Airship uses the LocaleThe combination of a language and country. A user’s locale is determined by their device settings. for various SDK operations. By default, the SDK automatically uses the device’s locale settings, but you can configure it to use the user’s preferred language or override it programmatically.

Configuring locale behavior

You can configure how Airship determines the locale by setting the useUserPreferredLocale option in your Airship config during takeOff.

By default, useUserPreferredLocale is false, and the SDK uses Locale.autoupdatingCurrent, which reflects the device’s current locale settings. When set to true, the SDK uses the first language from the user’s preferred languages list (Locale.preferredLanguages[0]), which is useful when you want the SDK to match the user’s language preference rather than the device’s current locale settings.

Configuring useUserPreferredLocale

var config = AirshipConfig()

// ... other config settings ...

// Use preferred language instead of current locale
config.useUserPreferredLocale = true

try! Airship.takeOff(config)
UAConfig *config = [UAConfig config];

// ... other config settings ...

// Use preferred language instead of current locale
config.useUserPreferredLocale = YES;

[UAirship takeOff:config error:&airshipError];

Overriding the locale

You can override the locale programmatically at runtime, which takes precedence over both the configured locale behavior and the device’s locale settings.

Overriding the locale

Airship.localeManager.currentLocale = Locale(identifier:"de")
UAirship.localeManager.currentLocale = 
    [NSLocale localeWithLocaleIdentifier:@"de"];

Clearing the locale override

To remove a locale override and return to using the configured locale behavior:

Clearing the locale override

Airship.localeManager.clearLocale()
[UAirship.localeManager clearLocale];

Getting the current locale

To retrieve the locale that Airship is currently using:

Getting the current locale

let airshipLocale = Airship.localeManager.currentLocale
NSLocale *airshipLocale = UAirship.localeManager.currentLocale;