hennes hennes - 2 months ago 15
iOS Question

How to find iOS locale hierarchy

The iOS system automatically picks the most suitable available localization for an app. For instance, when the user's locale is

en-IN
but the app only offers
en-GB
, that'll act as a fallback (as explained here).

My question is: Is it possible to look up these hierarchies somewhere?

The reasoning behind this question is that, for instance, I may have translations in
es-CO
,
es-CL
,
es-PE
, ... that are almost identical and instead of including separate string files for all of them, I'd like to just provide them for one common fallback locale. I know that I could simply use
es-419
in this exemplary case but it might not be that obvious in other scenarios.

Answer

Answering myself here:

Bundle.preferredLocalizations(
    from: ["es", "es-419", "es-AR", "es-CL", "es-CO", "es-MX", "es-PE"],
    forPreferences: ["es-PE"])

returns ["es-PE", "es-419", "es"] which means Peruvian Spanish fill fall back to es-419 and es in order.

Comments