Clement Bisaillon
Clement Bisaillon

Reputation: 5177

Get iPhone language in swift

In my app I need to get the phone language so that if the language of the phone is set to French, the content is in French and if it is in English the content would be in English.

Upvotes: 1

Views: 3151

Answers (2)

Kai Mattern
Kai Mattern

Reputation: 3085

Actually your approach is wrong. If you add languages to your project and use the means Apple provides for internationalization and localization, the switch is automatic.

Have a look here:

http://rshankar.com/internationalization-and-localization-of-apps-in-xcode-6-and-swift/

and here:

https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/LocalizingYourApp/LocalizingYourApp.html

The only time you may need the language, is if you query services that may serve results a language dependent way.

In that case your question is a duplicate: How to get current language code with Swift?

Upvotes: 5

Michael Dautermann
Michael Dautermann

Reputation: 89509

There's built-in support in Xcode for localization, so all you need to do is provide resources in French and resources in English and depending on the language the user is running, the correct set of resources will be loaded and used.

Instead of looking for a specific call in iOS or UIKit (and then swapping strings based on that specific function), why not follow the localizing directions given by Apple? They can be found here.

Upvotes: 2

Related Questions