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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top