手动获取特定的本地化字符串

时间:2016-04-06 08:02:37

标签: ios localization

假设我已经将所有内容放在Localizable.strings上用于多种语言。至于现在我使用NSLocalizedString并返回基于[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]设置的文本。现在我需要为每种语言获取特定的字符串。

假设我想将其置于选择语言设置并在用户按“提交”按钮时显示。因此它会显示一个对话框,其中包含“选择此语言?”的消息。用户选择的相应语言。

1 个答案:

答案 0 :(得分:0)

您可以通过手动加载来获取任何语言文件的任何翻译:

- (NSString *)localizedString:(NSString *)string forCountry:(NSString *)countryCode {
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings" inDirectory:nil forLocalization:countryCode];
NSBundle *dataBundle = [[NSBundle alloc] initWithPath:[bundlePath stringByDeletingLastPathComponent]];
return NSLocalizedStringFromTableInBundle(string, @"Localizable", dataBundle, nil); }

这有帮助吗?