Search code examples
iosinternationalization

UiTextView localized with xib strings file


I use base internationalization in xCode to manage multiple languages in my app.

In a xib file I've got this object :

Xrj-9E-2VK it's an UITextView

In the corresponding strings file :

"Xrj-9E-2VK.text" = "text translated in french"

But my text is still in English.

Any Suggestion ?


Solution

  • I've found the following workaround until Apple fixes this (serious) bug that still exists in iOS 7 :

    You actually need to 'mix' the 'base localisation method' (= preferred method for Xcode 5 & iOS 7) with the 'older' method of using the 'Localizable.strings' file

    1) create the file 'Localizable.strings' (File -> New -> iOS -> resource -> .strings file)

    2) use Xcode to create localised versions of this file for each language you use (select the file 'Localizable.strings', in File Inspector under 'Localization' click on the selection button next to each language you use).

    3) in your viewController create an IBOutlet @property for the UITextField :

    @property (weak, nonatomic) IBOutlet UITextView *localizedTextView;
    

    4) under 'viewDidLoad' add the following code :

    self.localizedTextView.text = NSLocalizedString(@"textFieldKey", @"comment for the translator");
    

    5) in each 'Localizable.strings' file add :

    "textFieldKey" = "the translated text you want to be put in the textField";

    That should do it !

    Keep in mind that Apple will probably fix this bug somewhere in the near future, in that case the translation will be taken from the 'base localised storyboard' (the one with the object references in, like "a8N-K9-eJb.text" = "some translated text". In that case you can delete the 'Localization.strings' file, and use base localisation again for a UITextField