0

我为 iPhone 制作了一个应用程序。在此用户可以在按钮单击时更改语言。但 NSLoalizedString 没有转换值。

代码是

-(IBAction)btn1pressed:(id)sender {
    SecViewController *sec = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil];
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];

    // NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]);


    languages =@"en";


    [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] synchronize];     
    NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]);

    // NSLog(@"%@", NSLocalizedString(@"Subhash", nil));
    [self.navigationController pushViewController:sec animated:YES];
}

-(IBAction)btn2pressed:(id)sender {
    SecViewController *sec = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil];
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];

    // NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]);


    languages = @"es";


    [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] synchronize];     
    NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]);

    //  NSLog(@"%@", NSLocalizedString(@"Subhash", nil));

    [self.navigationController pushViewController:sec animated:YES];
}

-(IBAction)btn3pressed:(id)sender {
    SecViewController *sec = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil];
    NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];

    // NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]);


    languages =@"ja";


    [[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] synchronize];     
    NSLog(@"%@", [userDefaults objectForKey:@"AppleLanguages"]);

    // NSLog(@"%@", NSLocalizedString(@"Subhash", nil));

    [self.navigationController pushViewController:sec animated:YES];
}
4

2 回答 2

0

尝试

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:languages,nil] forKey:@"AppleLanguages"];
于 2012-10-03T06:02:33.837 回答
0

使用 NSLocalizedString() 进行本地化。

同时给出相应的本地化字符串。

于 2012-10-03T06:13:54.610 回答