2
votes

After creating new cocoa application,I have added localization string files localizeFile.strings(English) and localizeFile.strings(Spanish)

In localizeFile.strings(English) file I added "TITLE" = "Hello!";

In localizeFile.strings(Spanish) file I added "TITLE" = "Hola!";

In my class I was trying to access the localized English text in actions with the following statements

-(IBAction)english:(id)sender
{
   // NSString *engText = [[NSBundle mainBundle] localizedStringForKey:@"TITLE" value:@"" table:nil];
    NSString *engText = NSLocalizedString(@"TITLE", nil);
    NSLog(@"engText %@",engText);
    [displayText setStringValue:engText];
}

-(IBAction)spanish:(id)sender
{
    NSString *spanText = NSLocalizedString(@"TITLE", nil);
      NSLog(@"spanText %@",spanText);
    [displayText setStringValue:spanText];
}

Here displayText is NSTextField and two actions in the same window.

I have seen in the console ,engText TITLE instead of engText Hello on clicking the buttons.

Can somebody guide me how can I get localized strings?Please help

1
Have you looked at all the resources on this page? - Rob Keniger
@Rob,I have seen that document,It is huge one,it is very vast and not mentioned neat procedure to do internationalization.For my understanding purpose,I am trying to do a very basic sample - Akbar

1 Answers

3
votes

It sounds like the application is not aware of localizeFile.strings. Did you declare the languages for the application? Is there a copy rule in your creation profile?

EDIT

You can add language here (red arrow): enter image description here

2nd EDIT

If you want use a language that isn't set on system level, you can do the following:

    // Assume you have defined constants, e.g. 1 - English, 2 - Espanol, 3 - ....
    switch (language) {
        case kLangEn: // =1
            path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
            break:
        case kLangEs: // =2
            path = [[NSBundle mainBundle] pathForResource:@"es" ofType:@"lproj"];
            break:
           // etc.
    }
    NSBundle *languageBundle = [NSBundle bundleWithPathath];
    NSString *str = [languageBundle localizedStringForKey:key value:@"" table:nil];