0

I'm trying to setup some basic localization via XCode.

I have done the following:

  1. Added a new Localize.strings file.
  2. Added French to my applications localization settings.FrenchThe one localized file is the Localize.strings file.
  3. I have added an 'Open File' localized string to my Localize.strings file.Localized Strings
  4. I have created an outlet, linked it to a button and added the following code:

Code (could not figure out how to get this inline with the bullet):

- (void) awakeFromNib
{
    // Add any code here that needs to be executed once the windowController has loaded the document's window.
    [openButton setTitle: NSLocalizedString(@"Open File", nil)];
}

My openButton is NOT null.

I have moved French (Francais) to be the prefered language in the language and text system preference. I launch the application and the title is localized, but my button is not!

Screenshot

Am I missing something stupid? Did I do something wrong here? From the tutorials I have read, this should do the trick, but it does not seem to be. Any suggestions?

Kyle
  • 17,317
  • 32
  • 140
  • 246

1 Answers1

2

It looks like you're missing a semicolon after your "Open File" line in the screenshot you posted. That will make the strings file invalid.

EDIT: The complete answer is that, in addition to the missing semicolon, NSLocalizedString looks for a file named "Localizable.strings", and in this case, the file was named "Localize.strings". To load localized strings from a file with a different name, you need to use NSLocalizedStringFromTable. In this case, the call would be NSLocalizedStringFromTable(@"Open File", @"Localize", nil);.

See Apple's Resource Programming Guide for the full documentation on how NSLocalizedString et. al. look for strings in files.

Michael Buckley
  • 4,095
  • 1
  • 26
  • 23
  • Hrrm, I've added the semicolon in each of the `Localize.strings` but, the app still shows like this: http://imgur.com/NUb0Hr9. I also did a `NSLog(@"Test: %@", NSLocalizedString(@"Open File", nil));` and it still comes out as "Open File". – Kyle Jul 20 '13 at 11:34
  • 1
    I just noticed that your file is named "Localize.strings". I believe the correct file name is "Localizable.strings", and I believe the filename does matter. If you're on 10.8 or later, the name of the enclosing lproj folder in your app's Resources directory matters too. It needs to be "fr.lproj", and not "French.lproj". – Michael Buckley Jul 20 '13 at 17:27
  • Yep, renaming the file did it. Thats crazy. Thanks for the help! – Kyle Jul 20 '13 at 17:36