Use localizations and locale codes in iOS SDK

To show each user a flow in a language they read, pass their languages to Adapty iOS SDK 4.5 or later. Users see a flow in their most preferred language that the flow has. A flow with none of these languages appears in its default locale.

On SDK 4.0–4.4, your app passes one locale code to getFlowConfiguration, and the SDK matches it exactly. To update your code, read Migrate Adapty iOS SDK to v4.5.

On SDK 4.5 or later, three cases follow other rules:

Pass the user’s languages to the SDK

AdaptyUI.getFlowConfiguration requires the preferredLocales parameter. Pass the user’s languages in it, most preferred first. Your app decides which languages to pass, such as the device languages or the language from a picker in your app.

let flowConfiguration = try await AdaptyUI.getFlowConfiguration(
    forFlow: flow,
    preferredLocales: Locale.preferredLanguages
)

Three rules decide which localization users see:

  • The SDK tries the user’s languages in order and matches the first one that the flow has. This is iOS language matching: the rules iOS uses to pick an app’s language. The SDK matches close variants of a language: de-AT matches de, and zh-TW matches zh-hant. Paywalls from the old Paywall Builder only use the user’s language with the highest priority.
  • Case and separators don’t matter: pt_BR, pt-BR, and pt-br match the same locale. Pass the values as iOS returns them.
  • With an empty list, or a list that matches none of the flow’s locales, the SDK uses the default locale.

Pass one of three lists. The list sets the order in which the SDK tries languages, but it can’t add a language that the flow lacks.

ValueThe flow appears inTrade-off
Locale.preferredLanguagesThe first device language that the flow has, even one your app isn’t translated intoThe flow can appear in another language than your app’s UI
Bundle.main.preferredLocalizationsThe language of your app’s UIThe list has one language. When the flow lacks it, users see the default locale. In an app with Base.lproj and no English localization, the list can contain Base.
[selectedLanguage] + Locale.preferredLanguagesThe language from the language picker in your app, then the device languages—

The two system lists give different results in two cases:

  • Your app has only English, and the flow has French and English. A French speaker sees French with Locale.preferredLanguages, and English with Bundle.main.preferredLocalizations.
  • Your app has Korean, and the flow doesn’t. A user with Korean, then Spanish, sees Spanish with Locale.preferredLanguages, and the default locale with Bundle.main.preferredLocalizations.
Tip

Don’t pass Locale.current.identifier. It contains one language, so the SDK has no other language to try. Its code has no script: zh_TW, not zh-Hant-TW. With this identifier, paywalls from the old Paywall Builder miss their zh-hant localization.

Most apps don’t pass localizationStrategy. Without it, the SDK uses .auto, which fits flows from the Flow & Paywall Builder and paywalls from the old Paywall Builder.

Tip

On SDK 4.6 or later, the app only keeps one non-default locale of a flow on the device. When the user switches to another locale, the SDK downloads that locale on the next getFlowConfiguration call. To download it before the app presents the flow, call getFlowConfiguration right after the user picks a language in your app.

Test which localization a user sees

To find out which localization a user sees, test the flow on a device:

  1. In a debug build of your app, print the locale of the flow configuration. It contains the code of the displayed localization:

    let flowConfiguration = try await AdaptyUI.getFlowConfiguration(
        forFlow: flow,
        preferredLocales: Locale.preferredLanguages
    )
    print("Flow locale: \(flowConfiguration.locale)")
  2. In the device settings, move the test language to the top of the language list.

  3. Run the app from Xcode, and open the flow.

  4. In the Xcode console, find the line that starts with Flow locale:. The dashboard shows the same code in lowercase: pt-br for pt-BR.

To test a language without a change to the device settings, pass a fixed preferredLocales list, such as ["pt-PT"], in a debug build.

When part of the flow still appears in the default locale, the displayed localization has no translation for that part. To fill the gaps, translate the missing rows in the Flow & Paywall Builder.

Select which locales to add to a flow

To cover the majority of users with the fewest locales, follow three rules when you add locales in the Select languages field:

  • Add a language without a region. For example, de covers German speakers in Germany, Austria, and Switzerland.
  • Only add a regional locale for a second translation of a language, such as fr-ca in addition to fr.
  • Add every language that your users read. The SDK doesn’t match one language to another, such as Catalan to Spanish. Catalan speakers see their next preferred language that the flow has, or the default locale.
Important

These rules need iOS or Android SDK 4.5 or later. Apps on any Adapty SDK from 4.0 to 4.4 pass one locale code. Their users can see a different localization of the same flow than users on SDK 4.5. Keep every code that those apps pass, such as an existing zh or pt-br.

Select codes for Chinese, Spanish, and Portuguese

The Select languages field has more than one code for Chinese, Spanish, and Portuguese. Add the codes from the table:

LanguageAddUsers see
Chinesezh-hans and zh-hant, not a new zh. Only add zh-hk for a separate Hong Kong translation.zh-hans in China and Singapore, and zh-hant in Taiwan, Hong Kong, and Macau.
Cantoneseyue, always with zh-hantyue on devices set to Cantonese, and zh-hant on devices set to Traditional Chinese. Without zh-hant, users on devices set to Traditional Chinese see written Cantonese.
Spanishes and es-419, not a new es-mxes in Spain, and es-419 in Latin America and the United States.
Portuguesept-br for Brazilian Portuguese, and pt for European Portuguesept-br in Brazil, and pt in Portugal.

If your flow is localized into multiple regional variants of the same language, serve a less region-specific locale as well — to catch language varieties that fall outside of those that you explicitly support. Without such a fallback, users from other regions are served a random locale in the language group — and you can’t set which one. For example, a user with es-MX can see es-ar, es-co, or es-es. To target such users, add the regionless es locale, or the pan-American es-419 locale.

To plan translations in stages, start from one of three sets. Each set contains the previous one.

SetLocalesTotal
Minimalen, es, pt-br, fr, de, it, ru, ja, ko, zh-hans, zh-hant11
ExtendedThe minimal set and tr, pl, nl, sv, da, no, fi, uk, ar, he, hi, id, th, vi, es-419, pt27
BroadThe extended set and cs, sk, hu, ro, el, bg, hr, sl, lt, lv, et, ca, kk, ms, fil, fa, ur, bn, ta, te, mr, fr-ca49

In these sets, users see the following locales:

  • In the minimal set, es covers Spanish speakers in every country, and pt-br covers Portuguese speakers in Portugal too.
  • In the extended set, es-419 and pt are second translations. With them, es serves Spain, and pt serves Portugal. Translate pt into European Portuguese.
  • Catalan and Malay speakers only see their language in its own locale: ca or ms. The SDK doesn’t show them Spanish or Indonesian instead.

Select the default locale

Users see the default locale when the flow has none of their languages. A new flow starts with en as its only locale and its default. To change it, set another locale as default.

Follow three rules for the default locale:

  • For users without a matching locale, select the language that most of them understand. Usually, that’s English, not the language of your main market.
  • Translate the default locale fully. Users without a matching locale see the whole flow in the default locale. Users with a matching locale see the flow in their language. Any untranslated part appears in the default locale.
  • Don’t select a language with two scripts, such as Chinese. Users of the other script may not read the default locale.

Select a localization strategy

Most apps don’t pass localizationStrategy, so the SDK uses .auto. This strategy applies iOS language matching to flows from the Flow & Paywall Builder, and the single-language rule to paywalls from the old Paywall Builder.

Under the single-language rule, the SDK only reads the language with the highest priority in preferredLocales. It tries the full code, then shorter codes (pt-br, then pt), and otherwise shows the default locale. A paywall from the old Paywall Builder keeps working under this rule, even after you republish it. To make the SDK try every language in preferredLocales, move the paywall to the Flow & Paywall Builder. Then serve the new flow from a flow placement.

To change how the SDK matches the user’s languages with the locales of the flow, pass one of the following values in the localizationStrategy parameter:

  • .system: every flow uses iOS language matching, paywalls from the old Paywall Builder included.
  • .legacy: every flow uses the single-language rule, not the exact matching of SDK 4.4. Don’t pass .legacy for flows from the Flow & Paywall Builder: it misses their locales with a region or a script, such as pt-BR.
  • .custom(resolver:fallbackResolver:): your code picks the localization.

Pick a flow’s localization in your own code

iOS language matching doesn’t cover every script. For example, when a device lists Azerbaijani in Cyrillic script (az-Cyrl) but not in Latin, a flow with az appears in its default locale. To show az instead, or to pick the localization by other rules of your own, create a type that conforms to AdaptyUICustomLocalizationResolver. Then pass it in the .custom(resolver:) value of the localizationStrategy parameter. Add import AdaptyUIBuilder to the file with the resolver.

Other Adapty SDKs match languages by other rules, so the same user can see different localizations of a flow on iOS and Android. To show the same localization on every platform, write a resolver that returns the same locale code as your app on the other platforms.

The following rules apply to the resolver:

  • The SDK doesn’t call the resolver for a flow with one localization. The flow appears in that localization.
  • The SDK calls resolve(for:from:) with the list that your app passed and an AdaptyUILocalizationSource with the flow’s locales and defaultLocale. The locales come in no fixed order.
  • To show a localization, return a code from locales or defaultLocale, spelled exactly the same, case included: ar, not AR.
  • If the resolver returns any other code or nil, the SDK uses the strategy in fallbackResolver. Without fallbackResolver, the SDK uses .auto.
  • The SDK can call the resolver off the main thread.
  • Return the code right away, without network requests or other slow work. The SDK waits for the resolver without a time limit, and the flow only appears after the resolver returns.

Locale code standard at Adapty

Adapty locale codes follow the BCP 47 standard: a language subtag, then an optional script or region subtag, separated by hyphens. The Select languages field shows the codes in lowercase: en (English), pt-br (Portuguese, Brazil), zh-hans (Simplified Chinese), and zh-hant (Traditional Chinese).

Localize custom paywalls and onboardings

SDK 4.5 only changes the localization rules for flows. Custom paywalls and onboardings work as in SDK 4.4.

Pick a custom paywall’s remote config by language

getFlow has no locale parameter. For a custom paywall, it returns every configured localization in flow.remoteConfigs. Each entry has a locale code and the config content (jsonString, or the parsed dictionary). Pick the entry that matches the user, with your own fallback:

do {
    let flow = try await Adapty.getFlow(placementId: "YOUR_PLACEMENT_ID")
    let config = flow.remoteConfigs.first(where: { $0.locale == "en" })
        ?? flow.remoteConfigs.first
    // read your values from config?.dictionary
} catch {
    // handle the error
}

Adapty stores those locale codes in the format described in Locale code standard at Adapty. The SDK doesn’t match remote configs against a locale, so which entry to apply is up to your app.

Pass a locale to an onboarding

Warning

Onboardings are deprecated starting with Adapty SDK v4. Build flows instead: unlike onboardings, which run inside a WebView, flows render natively on the device — smoother animations, a consistent native look and feel, faster load times, and no WebView runtime dependency.

getOnboarding keeps its locale parameter in SDK 4.5. When you pass a locale to getOnboarding, the server picks the localization:

  1. The locale string is converted to lowercase and all the underscores (_) are replaced with hyphens (-)
  2. Adapty looks for the localization with the fully matching locale code
  3. If no match is found, Adapty takes the substring before the first hyphen (pt for pt-br) and looks for the matching localization
  4. If no match is found again, Adapty returns the content for the onboarding’s default locale

This way pt_BR, pt-BR, and pt-br all resolve to the same onboarding localization.

Why this is important

There are a few scenarios when locale codes come into play — for example, when you’re trying to fetch the correct paywall for the current localization of your app.

As locale codes are complicated and can vary from platform to platform, we rely on an internal standard for all the platforms we support. However, because these codes are complicated, it is really important for you to understand what exactly are you sending to our server to get the correct localization, and what happens next — so you will always receive what you expect.

Locale code standard at Adapty

For locale codes, Adapty uses a slightly modified BCP 47 standard: every code consists of lowercase subtags, separated by hyphens. Some examples: en (English), pt-br (Portuguese (Brazil)), zh (Simplified Chinese), zh-hant (Traditional Chinese).

Locale code matching

When Adapty receives a call from the client-side SDK with the locale code and starts looking for a corresponding localization of a paywall, the following happens:

  1. The incoming locale string is converted to lowercase and all the underscores (_) are replaced with hyphens (-)
  2. We then look for the localization with the fully matching locale code
  3. If no match was found, we take the substring before the first hyphen (pt for pt-br) and look for the matching localization
  4. If no match was found again, we return the content for the paywall’s default locale

This way an iOS device that sent 'pt_BR', an Android device that sent pt-BR, and another device that sent pt-br will get the same result.

If you’re wondering about localizations, chances are you’re already dealing with the localized string files in your project. If that’s the case, we recommend placing some key-value with the intended Adapty locale code in each of your files for the corresponding localizations. And then extract the value for this key when calling our SDK, like so:

// 1. Modify your Localizable.strings files

/*
Localizable.strings - Spanish
*/
adapty_paywalls_locale = "es";
/*
Localizable.strings - Portuguese (Brazil)
*/
adapty_paywalls_locale = "pt-br";
// 2. Extract and use the locale code
let locale = NSLocalizedString("adapty_paywalls_locale", comment: "")
// pass locale code to AdaptyUI.getViewConfiguration or Adapty.getPaywall method

That way you can ensure you’re in full control of what localization will be retrieved for every user of your app.

Implementing localizations: the other way

You can get similar (but not identical) results without explicitly defining locale codes for every localization. That would mean extracting a locale code from some other objects that your platform provides, like this:

let locale = Locale.current.identifier
// pass locale code to AdaptyUI.getViewConfiguration or Adapty.getPaywall method

Note that we don’t recommend this approach due to few reasons:

  1. On iOS preferred languages and current locale are not identical. If you want the localization to be picked correctly you’ll have to either rely on Apple’s logic, which works out of the box if you’re using the recommended approach with localized string files, or re-create it.
  2. It’s hard to predict what exactly will Adapty’s server get. For example, on iOS, it is possible to obtain a locale like ar_OM@numbers='latn' on a device and send it to our server. And for this call you will get not the ar-om localization you were looking for, but rather ar, which is likely unexpected.

Should you decide to use this approach anyway — make sure you’ve covered all the relevant use cases.