Im making an interactive children's story that only uses custom graphics and narrations.
I have all graphics in both English and Spanish.
I dont have any non-custom buttons, no text fields, not a single "standard" Apple app UI element anywhere. Everything is a custom PNG file.
Im simply looking for a method to allow the user to change from English to Spanish or vice-versa.
I created a custom English and a Spanish button already, which will highlight when pressed.
The app will (from what Ive read need to be restarted) and the app will then present its Spanish pages (and the Spanish text embedded in the PNG). Spanish narration will ensue.
At any point the user can elect to hit the English language button, and return to English if so desired.
Tabtale's "Mermaid Princess" app does this extremely well, and is far more than I need, but is a good example of what Im after. You click a button, change your region, the app restarts, and all the custom text and narrations result for the region youve selected.
I only have two regions (languages) so my need is much simpler.
But how in the world to actually pull this off ?
Cheers !
OK, this was much harder than I had expected…
Basically I am exchanging NSBundle's method that will be invoked by
NSLocalizedString(…)
by using a category on NSBundle and a technique called isa-swizzelingNSBundle+Language.h
NSBundle+Language.m
The AppDelegate will listen for
LANGUAGE_WILL_CHANGE
notifications, set the language and broadcast a notificationLANGUAGE_DID_CHANGE
AppDelegate.m
A BaseViewController will post
LANGUAGE_WILL_CHANGE
and listen forLANGUAGE_DID_CHANGE
BaseViewController.h
BaseViewController.m
Now any view controller that subclasses
BaseViewController
can implementlanguageDidChange
to callNSLocalizedString
.ViewController.m
Ad you see, I am simply localising the image name, I added the images
en_image.png
andes_image.png
to the Images asset bundle and map them in the localizable stringsand
Result
You'll find this example code here: https://github.com/vikingosegundo/ImmidiateLanguageChange