Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 407
Jean Lebrument Avatar asked Oct 17 '13 12:10

Jean Lebrument


People also ask

How do I localize Xib files?

strings files from the xib, which make localization pretty straight forward. Right click on the xib file in Xcode, and choose Get Info . Select the General tab and on the bottom click Make File Localizable . Then you will be able to add localizations by clicking Add Localization on that same tab.

What does localized string mean?

A localized string can have different values depending on the language in which the project is being build. There are two categories of localized strings: the strings included in the installation package's UI, common to every MSI file.

How do I use localized strings in SwiftUI?

Use it in custom SwiftUI views to make them ready for localization. Enable the "Use Compiler to Extract Swift Strings" build setting to extract LocalizedStringKeys from code when exporting for localization in Xcode. Format your strings to internationalize your code, and style them with Markdown.

What is localized string key SwiftUI?

The key used to look up an entry in a strings file or strings dictionary file.


1 Answers

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

like image 165
Ronny Webers Avatar answered Oct 09 '22 10:10

Ronny Webers