I have a database on the server that contains all the languages keywords that I use inside my applications and these languages could be changed any time.
In the language table of database there is column
for Language
(id , key, value, lang)
.
In the android application I read the language from device and it returns for example en-GB
or en-US
.
But in the iOS application I can't get the language like the above example , It always returns just the language (en , es, fr
).
So I can't query to database to get the language specified keywords on the iOS application. Because the languages on the database is en-GB, en-US style.
var langId: String? = NSLocale.preferredLanguages().first as? String
How can I get the language with more details ?
You can use Locale. getDefault(). getLanguage(); to get the usual language code (e.g. "de", "en").
This can be done by navigating to the device Settings, select an app, select language, and change the chosen language.
Locale encapsulates information about linguistic, cultural, and technological conventions and standards.
An object representing information about linguistic, cultural, and technological conventions that bridges to Locale ; use NSLocale when you need reference semantics or other Foundation-specific behavior.
No need an extra effort, just use the following as per your requirement.
Locale.current.identifier //en_US
Locale.current.collatorIdentifier //en-US
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With