Reputation: 136211
My team is building an app for Android and iOS. The application receives several notifications from the server, in various forms like push notifications and UI popups.
In order to send the messages in the right language, I would like the apps in both platforms to send me the device language in the same format.
For example, English can be en
or eng
or even English
, but it must be the same for both devices.
Is there a language name format supported by both iOS and Android? If so, what are the calls for the device language in both platforms?
Upvotes: 0
Views: 1312
Reputation: 136211
As it turns out, iPhone's IETF BCP 47 language codes can be converted to Android's ISO-639-2 codes.
I will accept both inputs in their native form and convert iPhone's BCP 47 to ISO-639-2 on the server side.
Upvotes: 1
Reputation: 1574
Android:
Locale.getDefault().getLanguage() ---> en
Locale.getDefault().getISO3Language() ---> eng
Locale.getDefault().getCountry() ---> US
Locale.getDefault().getISO3Country() ---> USA
Locale.getDefault().getDisplayCountry() ---> United States
Locale.getDefault().getDisplayName() ---> English (United States)
iOS
NSString *language = [[NSLocale preferredLanguages] firstObject]; // ---> en
documentation: https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/Articles/ChoosingLocalizations.html
So you can use "en" for English. There must be something available for ios to get the full language name but I haven't used it before.
Upvotes: 4