I have a requirement where my backend supports only few locales, So when I am uploading some data I am suppose to tag the locale, so I should feed the supported locales to the app, And How do I do it? could somebody help me out
Asked
Active
Viewed 100 times
1 Answers
1
I had a similar requirement, the implementation was simple. We used to pass the locale in the header of our API requests along with the Auth headers. Both these functions below are class functions of the class AppHelper
Code for getting the localisation:
class func getLocalisation() -> String? {
let language = Bundle.main.preferredLocalizations.first
if let splittedString = language?.split(separator: "-"){
return String(splittedString[0])
}
return nil
}
Using the locale and Attaching it to the header.
class func getAuthHeaders() -> Dictionary<String, String> {
var headers = Dictionary<String, String>()
if let authkey = AppHelper.getAuthKey() {
headers[Constant.authKeyHeader] = authkey
}
if let localisation = AppHelper.getLocalisation() {
headers[Constant.localisation] = localisation
}
return headers
}
Hope this helps. Happy Coding.

Md. Ibrahim Hassan
- 5,359
- 1
- 25
- 45