I am using localization for english and spanish language in my sample application. I have added Localizable.strings class for both english and spanish. I know it is possible to localized an image, XIBs and label text. But I would like to know that is it possible to localize an iPhone app without localized their XIB's, even what's the need to make XIB localized ? Or can we give the button title as NSLocalizedString(@"TITLE", nil) in Interface Builder ? I know this won't be proper way for doing this. Please suggest me for further proceeding.

Thanks.

有帮助吗?

解决方案

Yes you can localize an App without localizing the XIBs.

You will need to create an outlet for every label, button, textview,... Then in the viewDidLoad set the correct localized strings:

-(void) viewDidLoad {
    [super viewDidLoad];

    self.nameLabel.text = NSLocalizedString(@"name:", @"name label");
    [self.saveButton setTitle:NSLocalizedString(@"save", @"Save button title.") forState:UIControlStateNormal];
}

This is the way I do it, since changing all the localized XIB will just take to long and with autolayout you can make sure that everything will fit.

其他提示

The reason for localising XIB files is that the text for different languages are different lengths so the size of views in the UI will need to change. This can be handled in the XIB or in code (such as sizeToFit and reposition / auto-layout constraints).

Technically you could also use NSLocalizedString for getting localised image names if you wanted to...

You do not need XIBs to localize strings eg. for button you use like

[button setTitle:NSLocalizedString(@"Title","description") forState:UIControlStateNormal];

then you define in Localizable.strings files what to show for which language

in Localizable.strings (spanish)

"Title" = "<Title in spanish>";
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top