0

I have some features and Strings depending on the Region of the App. That region also speaks English . As per my knowledge NSLocalization only depends on the language user chooses. I want to change the String depending on the region. How to achieve it ? The solution which is available not works on iOS8+ .

Thanks in Advance

coreDeviOS
  • 1,468
  • 2
  • 14
  • 27

2 Answers2

0

I have used below reference and my code works with the Spanish and English language.

I have set these two languages and i found this is worked.

tutorial link

I know you tried but there is some problem with your code because i had used and it works perfect.

Hope this will help you a lot. thank you.

JAY RAPARKA
  • 1,353
  • 2
  • 13
  • 33
  • Your case is different . You have two different language which is cool . I have same language English . But want to localise depending on the "Region" – coreDeviOS Oct 13 '15 at 06:55
  • @coreDeviOS i still didn't get properly your question region wise you want to change but its not english like abhinav said. – JAY RAPARKA Oct 13 '15 at 07:31
  • english for canada and english for franch both are different language so you have to create string file for all the language which you want to add in app. – JAY RAPARKA Oct 13 '15 at 07:32
  • and if there is any direct way without creating string file than i don't know that way. sorry for that. – JAY RAPARKA Oct 13 '15 at 07:33
  • That doesn't work , Localization totally works on the device "Language" Settings . It will not consider the Region Settings. Region settings in only used for Currency and other kind of string display but it will not contribute in Localizing the strings. – coreDeviOS Oct 13 '15 at 07:36
0

You need to build your custom logic around it. This is how I would do it:

Step 1: Keep all the localizations in a plist on server. Just to make data dynamic. There would be file for each language & region. Something like myLocalization_en_CA.plist & myLocalization_en_FR.plist. Typically this can be done in DB which is easy to maintain.

Step 2: On app launch, load this localization plist from server and save it locally. May be in Documents directory. Key thing here is, based on your device region, you would need to download all the localisation files that speaks that language. This step can be streamlined, if at launch time, you could know the exact language to be used in that region. For instance, in Canada, both English and French is spoken, so if at launch time you can deduce the language, say French, then fetch only myLocalization_en_FR.plist.

Step 3: Write a utility method and pass the key for the current label/string to be shown on screen. This method should also take a parameter like fr_CA covering both locale and region and then pick up the file by merging myLocalization_ with the passed string.

Step 4: Once correct file is picked in above utility method, simply fetch the value for the passed key.

Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • I don't want to make any server call. And its not proper way. – coreDeviOS Oct 13 '15 at 07:37
  • 1
    Making a server call to fetch the updated localisation is always a standard industry practice. This gives you freedom of changing your application text without releasing a new client build. As you already noticed, default method `NSLocalizedStringWithDefaultValue` works on the device language. So, you have to stick to some custom solution. If you do not want to load it from server, you can keep all these localisation in your bundle which, I personally, won't recommend. – Abhinav Oct 13 '15 at 07:44
  • Your solution is correct. But i don't want to create my own logic for localization. As iOS handles it is much efficient way. I want to change the decision making of NSLocalization . As i also have some storyboard localization changes . – coreDeviOS Oct 13 '15 at 08:01