2

I've come across with the problem where language settings is in app, that user can change it at anytime, but..

when i change it with using this code e.g

[[NSUserDefaults standardUserDefaults] setObject:@[@"de", @"en", @"it"] forKey:@"AppleLanguages"];

it do not effect until restarting the application becuase bundle is already loaded in appDelegate, right?

so i tried this solution

https://stackoverflow.com/a/20257557/2839104

but already loaded viewControllers do not effected, so...

how can i update app language without restarting it and without changing NSLog usages with something else? is there any way for it?

I would appreciate any comments.

Community
  • 1
  • 1
cihangirs
  • 55
  • 1
  • 12
  • What's wrong with restarting the app? Do you really need the user to change the setting from within your app (what's wrong with the system setting)? You are allways free to implement your own localization mechanism. – lupz Jan 13 '15 at 12:55
  • actually just because it is possible to change the preferred language in-app without restarting it, it is more fancy. so at this point my question is, should i change localization mechanism with using something else than NSLocalizedString or is there any way to change language immediately without replacing NSLocalizedString usages already done before. – cihangirs Jan 13 '15 at 13:01

1 Answers1

1

You have to implement a class that will loads each localizable.string corresponding to the languages available in the project.

Then you create a viewController to allow selecting a new language.
When user select a language, you'll have to reload the language labels and notify each controllers that it has to refresh itself.

I made this inside some of my applications.

I created a macro to add my viewController as delegate to the languageManager.

David Ansermot
  • 6,052
  • 8
  • 47
  • 82
  • I actually have a viewController which allows selecting a new language. what do you mean refreshing controller and also reloading the language labels. For language labels i use NSLocalizedString. – cihangirs Jan 13 '15 at 13:15
  • You'll have to do a macro or calling method from you translation manager instead of NSLocalizedString. Like this it's the translationManager that returns the translation. – David Ansermot Jan 13 '15 at 13:16
  • so let me be clear, does your suggestion means replacing each NSLocalizedString with a manager method at the end of this implementation you mentioned? – cihangirs Jan 13 '15 at 13:31
  • Yes this is exactly that. In my apps I've named it "LL(__key__)" like "Local language" – David Ansermot Jan 13 '15 at 13:33
  • actually i'm looking for a way without replacing NSLocalizedString usages – cihangirs Jan 13 '15 at 13:51
  • You can't. I've already searched for a solution but as it's the app @ the launching that loads only the right localizable.strings. Trust me, no other way – David Ansermot Jan 13 '15 at 14:09