3

I'm trying to use NSLocalizedStringFromTable but with no results. I've got created Profile.strings file, clicked localized, in project settings I add Polish and English languages, so my file has 2 "files" inside and I typed the same strings with other values but when I switch languages and restart app there is still one localization used (Polish).

Profile.strings in Xcode:

Profile.strings
    Profile.strings (Polish)
    Profile.strings (English)

Polish:

"fullName.placeholder" = "Imie i nazwisko";

"emailAddress.placeholder" = "Adres email";

"phoneNumber.placeholder" = "Numer telefonu";

English:

"fullName.placeholder" = "Full name";

"emailAddress.placeholder" = "Email address";

"phoneNumber.placeholder" = "Phone number";

To get value I call:

NSLocalizedStringFromTable(@"fullName.placeholder", @"Profile", @"");

Any time I call this I've got value from Profile.strings (Polish)

What I'm doing wrong?

Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
  • 1
    try again by removing app from device/simulator and relaunch the xcode – freelancer Feb 06 '14 at 18:26
  • just for more understanding read this http://www.cocoawithlove.com/2011/04/user-interface-strings-in-cocoa.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+CocoaWithLove+%28Cocoa+with+Love%29 – Suny Feb 06 '14 at 18:27
  • 1
    I know how `NSLocalizedString()` works, but I don't know why `NSLocalizedStringFromTable()` doesn't work. – Tomasz Szulc Feb 06 '14 at 18:30
  • @freenalcer, Thanks! `Reset Content and Settings`. Please add answer in separated post and I will mark it up. – Tomasz Szulc Feb 06 '14 at 18:31

2 Answers2

6

try to Reset Content and Settings of simulator it will work (:

freelancer
  • 1,658
  • 1
  • 16
  • 37
4

Maybe you're not changing the language correctly. Try doing it in code. Like this:

- (void) setLanguage:(NSString*) l{
    for (NSString *language1 in [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]) {
        NSBundle *bundle1 = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language1 ofType:@"lproj"]];
        NSLog(@"%@: %@", language1, NSLocalizedStringFromTableInBundle(@"left", @"Localizable", bundle1, nil));
    }
    NSBundle *bundle1 = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:l ofType:@"lproj"]];
    /*
   if ([l isEqualToString:@"en"]) {
       bundle1 = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"English" ofType:@"lproj"]];
   }
    */


    if (bundle1 == nil)
        //in case the language does not exists
        [self resetLocalization];
    else
        bundle = bundle1;
    NSMutableArray *langs = [NSMutableArray arrayWithArray: [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]];
    [langs removeObject:l];
    NSMutableArray *newLangs = [NSMutableArray arrayWithObject:l];
    [newLangs addObjectsFromArray:langs];

    [[NSUserDefaults standardUserDefaults] setObject: newLangs forKey:@"AppleLanguages"];
}

And then you can do

[self setLanguage:@"en"];

Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79
Darkslave
  • 111
  • 5