Programming Languages Hacks

Importanti regole per linguaggi di programmazione rilevanti come Java, C, C++, C#…

  • Subscribe

  • Lettori

    I miei lettori abituali

  • Twitter

iOS NIB Localization in Localizable.strings

Posted by Ricibald on June 3rd, 2011

Scenario:

I want to localize my app AllSync but I was taken by a little frustration.

Following this good guide you can see that there are two main way to localize your iOS (iPhone/iPad) app:

  • localize strings using Localizable.strings
  • localize single nib file creating one version for each
The second point is very frustrating for three reasons:
  • you have to mantain updated all version of your nib localized files
  • there are specialized sites like icanlocalize that translates only your Localizable.string, not your nib files
  • you have to take care about the resulting layout of single translation
The problem:
I want to localize my nib files in the same way of using Localizable.strings

A possible solution can be to externalize in code every text setting but is a tedious process and you can’t use the flexibility of xcode 4. The real solution I hope will be used by many of you is this:

The solution:

Create an extended version of iOS user control that automatically translates every single text

Simple to obtain: just see this extended UIButton

@interface UIButtonThemed : UIButton
@end

@implementation UIButtonThemed
- (id)initWithCoder:(NSCoder *)aDecoder {
    if ((self = [super initWithCoder:aDecoder]))
	{
        self.titleLabel.adjustsFontSizeToFitWidth = YES;
        NSString* text = NSLocalizedString(self.titleLabel.text, nil);
        [self setTitle:text forState:UIControlStateNormal];
        [self setTitle:text forState:UIControlStateHighlighted];
        [self setTitle:text forState:UIControlStateDisabled];
        [self setTitle:text forState:UIControlStateSelected];
	}
	return self;
}
@end

You can use it inside xcode 4 configuring the base class for your control:

Then you can see my italian Localizable.strings:
"Sync" = "Sincronizza";
"Settings" = "Impostazioni";
"Help" = "Guida";
"Share" = "Condividi";
"Rate us" = "Votaci";
"Follow us" = "Seguici";
And the corresponding result:

9 Responses to “iOS NIB Localization in Localizable.strings”

  1. Maik Mwes Says:

    Hello,

    you can extract strings from your nib with ibtool –generate-strings-file name.strings name.xib via the command line .
    Another more comfortable way is translationWizard. May have a look on it: Http://www.moewes.net/translationWizard

    Bye
    Maik

  2. Roberto Mazzone Says:

    Con xCode 4.2 e il nuovo iOS 5, basta solo aggiungere le localization nella main storyboard e si aprir una specie di men, da questo men possibile cambiare direttamente lingua tramite la main storyboard, senza usare codici ne niente

  3. http://xbox-consoles.org/microsoft-consoles/mech-warrior-4-mech-paks-inner-sphere Says:

    Title…

    This is my Excerpt…

  4. Jay Says:

    You can actually automate this entire process and not have to touch any line of code or command line by using TraductoPro app http://www.traductoapp.com/traductopro

  5. optometrist in winnipeg Says:

    Keep on working, great job!

    Visit my web-site :: optometrist in winnipeg

  6. plagiarism avenger|plagiarism avenger review|plagiarismavengerreview Says:

    You can certainly see your skills within the paintings you write. The arena hopes for even more passionate writers like you who are not afraid to say how they believe. At all times follow your heart.

  7. summ3r Says:

    Hi,
    If you’re interested to collaboratively translate web software, PC software, mobile software or any other type of software, I warmly recommend POEditor, a localization platform that my team developed not long ago, which will probably help you get your translation projects done a lot faster and easier.
    POEditor has an intuitive work interface, which makes it easy to use for technically inexperienced translators. It is perfect for crowdsourcing and it has a lot of management-oriented features, that give full control over the translation workflow, which you can find enlisted on our website here:
    http://poeditor.com/
    You can import from multiple language file formats or just use our REST API.
    Feel free to try it out and recommend it to developers and everyone who might find it useful.

  8. http://advancedtestoboostblog.org Says:

    Hey there would you mind stating which blog platform you’re using?
    I’m going to start my own blog soon but I’m having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your design seems different then most blogs and I’m
    looking for something unique. P.S Sorry for getting off-topic but I had to
    ask!

  9. Електронно заключване с чип за Вашия вход. Повишете сигурността на дома си! Цени от 100 лв. - http://escalator.bg Says:

    I don’t even know how I ended up right here, however I believed this publish used to be good. I don’t recognize who you might be but certainly you’re going to a famous blogger if you happen to are not already. Cheers!

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>