Locale

Configure locale behavior and override the default locale that Airship uses for messaging and analytics.

The Airship SDK is localized in 48 different languages for all strings included within the SDK. By default, the SDK automatically uses the device’s or app’s configured LocaleThe combination of a language and country. A user’s locale is determined by their device settings..

Airship uses the locale for various locale-sensitive operations:

  • Message localization: Selecting the appropriate language variant for push notifications, in-app messages, and Message Center content
  • Analytics reporting: Recording the user’s locale for segmentation and reporting
  • SDK strings: Displaying SDK-generated UI elements in the user’s language

Apps can override the locale to use a different locale than the device’s current setting. This is useful when your app provides its own language selector or needs to match Airship’s locale to your app’s locale setting.

Override the locale

You can override the locale programmatically at runtime, which takes precedence over the device’s locale settings. Use standard locale identifiers (e.g., “en”, “en-US”, “de”, “fr-CA”).

// Set locale to German
Airship.locale.setLocaleOverride("de");

// Set locale to Canadian French
Airship.locale.setLocaleOverride("fr-CA");

// Set locale to US English
Airship.locale.setLocaleOverride("en-US");
 Note

Locale overrides persist across app sessions. Once set, the override remains active until explicitly cleared or changed.

Clear the locale override

To remove a locale override and return to using the device’s locale:

Airship.locale.clearLocaleOverride();

Get the current locale

To retrieve the locale that Airship is currently using:

var locale = await Airship.locale.locale;
debugPrint("Current Airship locale: $locale");

Example: Sync with app language

If your app provides a language selector, you can sync Airship’s locale with the user’s selection:

// When user changes language in your app
void onLanguageChanged(String languageCode) {
  // Update your app's locale
  // ... your app-specific code ...
  
  // Update Airship's locale to match
  Airship.locale.setLocaleOverride(languageCode);
  
  debugPrint("Language changed to: $languageCode");
}

// When user resets to device default
void onResetToDeviceLanguage() {
  // Clear Airship's locale override
  Airship.locale.clearLocaleOverride();
  
  debugPrint("Reset to device locale");
}