3

I am trying to change the app language from within the app. I am able to achieve this and change the text as per the changed localization but the localized images are not loaded until i restart my app.

1) The localized images are placed in en.lproj and vi.lproj folders.

2) The images are displayed in table view and the table view is reloaded after language change.

still the localized images are not fetched.

Logs that i try to print >>

NSBundle /Users/admin/Library/Application Support/iPhone Simulator/7.0/Applications/863CF1CB-C9C5-4257-8D6E-DA104C8EC849/test.app/en.lproj (not yet loaded)

NSBundle /Users/admin/Library/Application Support/iPhone Simulator/7.0/Applications/863CF1CB-C9C5-4257-8D6E-DA104C8EC849/test.app/vi.lproj (not yet loaded)

Thanks.

Swati
  • 2,870
  • 7
  • 45
  • 87
  • As far as I know, the selected language is a system wide setting. When you change the language within the settings app, iOS will "reconfigure" itself and all running apps (restart them). At runtime you can select the localization dict for strings like I did it here: http://stackoverflow.com/a/22838176/1167428. We had problems with images too, so we ended up to not use the systems localization support, but instead load the images from our own localization folders. This way we were even able to implement language regions (like en, en-UK, en-US, en-CA) that seemed to be not supported natively. – lupz Nov 24 '14 at 10:16

2 Answers2

2

There is one simple workaround

Use different images with different name according to language and load the image according to the language chosen from code.

e.g. In tableView cellForRowAtIndexPath Method

if(language = english) {
imageName = @"logo_english";

}

else if (language = french) {
imageName = @"logo_french";
}

Otherwise use apple native localisation of images which takes effect after app restart.

Dinesh Kaushik
  • 2,917
  • 2
  • 23
  • 36
  • the logic is fine but if text can be fetched from localized file without restart then can we work with images in same way... [dont want to change image names] – Swati Nov 24 '14 at 10:17
  • To improve this, one could use a utility function that appends the localization mark (file suffix/prefix, folder) to the resource name. It helps to keep localization handling [DRY](http://de.wikipedia.org/wiki/Don%E2%80%99t_repeat_yourself). – lupz Nov 24 '14 at 10:35
1

How are you loading your images? If you want to override the language chosen for the system, you can use -[NSBundle pathForResource:ofType:inDirectory:forLocalization:] to specify the localization you want to use when fetching a resource.

Thomas Deniau
  • 2,488
  • 1
  • 15
  • 15