Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get detailed language of device in swift

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 ?

like image 575
Morteza Soleimani Avatar asked May 09 '15 14:05

Morteza Soleimani


People also ask

How do I find current device language?

You can use Locale. getDefault(). getLanguage(); to get the usual language code (e.g. "de", "en").

How do I get the Swift language on my phone?

This can be done by navigating to the device Settings, select an app, select language, and change the chosen language.

What is locale in iOS Swift?

Locale encapsulates information about linguistic, cultural, and technological conventions and standards.

What is NSLocale?

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.


1 Answers

No need an extra effort, just use the following as per your requirement.

Locale.current.identifier //en_US
Locale.current.collatorIdentifier //en-US
like image 101
Tapas Pal Avatar answered Nov 10 '22 06:11

Tapas Pal