0

I'm trying to build a library that will allow for dynamic loading of Localizable.strings files. If the views are being developed programmatically, then it's not a problem, as I could build a separate NSBundle, store the .strings files inside, and use NSLocalizedStringFromTableInBundle.

The problem I'm having lies with Storyboards. I haven't managed to find a way to specify which .strings file to load from (rather than using the default .strings that Apple uses).

Does anyone know of a solution for this? It doesn't even have to follow the same approach, as long as I can dynamically update the strings on a Storyboard. (The strings will be pulled down from an external source via API call upon app launch)

Andy Shephard
  • 1,726
  • 17
  • 26
  • Check out this answer on [Base Internationalizing][1]. [1]: http://stackoverflow.com/a/12731497/2715819 – RishiG Sep 15 '14 at 20:09
  • I took a different approach. While the Base Internationalizing guide does help, it leaves me with a .strings file full of Object IDs, which could be impractical (Not sure why Apple wouldn't allow users to specify the objectName and use this set value instead). – Andy Shephard Sep 15 '14 at 20:32

1 Answers1

0

Loading strings from a separate bundle/strings source

In order to overcome the issue I had, I created IBOutlets for each object on the Storyboard's collection of views. Within each view's implementation file, I programmatically set the text/values of each object by using NSLocalizedStringFromTableInBundle, which allows me to specify a custom bundle, which can be populated with strings files.

In the event that a project has both programmatic and storyboard developed views, this approach also allows for the usage of only one Localizable.strings file, rather than mixing Storyboard-generated files, and files used only for programmatic views (if applicable).

Loading strings into an app via API call

Unfortunately, the above approach doesn't allow for strings to be downloaded from an external source via API call. The reason for this being, Apple doesn't allow for any files in the app bundle to be edited after being built.

Because of this, the solution would be to build out a data structure within the app's DocumentsDirectory, and edit this whenever necessary, then force the app to use this file/library in order to get localized strings. Not a pretty solution, but it's the best approach I can think of.

Community
  • 1
  • 1
Andy Shephard
  • 1,726
  • 17
  • 26