简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM