Locale.preferredLanguages returns en first sometimes

Viewed 393

When calling Locale.preferredLanguages sometimes it returns en first when I have multiple languages please see the image below.

enter image description here

You can see on the left my order is Spanish then English but the array Locale.preferredLanguages is returning English, Spanish.

Does anyone know why this happens?

1 Answers

The documentation for Locale.preferredLanguages doesn't say anything about the order of the languages returned. That seems absurd, but there it is.

It looks like the Bundle class' preferredLocalizations(from:forPreferences:) function does order it's responses in user preference order⁽¹⁾, so it sounds like you may need to pass in an array of all the locales your app supports to your Bundle and have it give you the results in user-preference order.


⁽¹⁾ To quote the docs: "Return Value: An array of locale identifiers, ordered according to user preference."

Related