iPhone/iOS : How can I get a list of localized strings in all the languages my app is localized in?

标签 iphone ios localization nslocalizedstring

我需要向我的服务器发送特定字符串的本地化列表。

意思是,如果我的应用程序有一个字符串 Foo,在英语中本地化为 @"Foo",在俄语中本地化为 @"Фу",我想向服务器发送如下列表:

  • 字符串富:
    • 英语:“Foo”
    • 俄语:“Фу”

我认为我需要能够做的是:

  1. 为我的应用本地化的每种语言枚举本地化字符串
  2. 获取每种语言的 Foo 本地化版本

我该怎么做 (1),我该怎么做 (2)?

最佳答案

您可以通过将 English.lproj/Localizable.strings 作为字典读取并获取其键来检索所有字符串键:

NSString *stringsPath = [[NSBundle mainBundle] pathForResource:@"Localizable" ofType:@"strings"];
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:stringsPath];

要获取每种语言的翻译,您可以遍历每个英语键的语言并使用 NSLocalizedStringFromTableInBundle:

for (NSString *language in [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]) {
    NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]];
    NSLog(@"%@: %@", language, NSLocalizedStringFromTableInBundle(@"Testing", @"Localizable", bundle, nil));
}

关于iPhone/iOS : How can I get a list of localized strings in all the languages my app is localized in?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6310487/

相关文章:

iphone - 在 Objective-C 中通知自定义委托(delegate)类

iphone - 从 NSOperationQueue 中取消 NSOperation 导致崩溃

iphone - 带有 Web 服务的核心数据推荐模式?

ios - 如何将 Cocos2d Sprite Frames 封装在一个类中?

ios - 在多个 Storyboard 中使用相同的 UIViewController

localization - 用于 gettext 支持的 CMake 模块?

iphone - 无法将私有(private)框架添加到项目。它说找不到框架

ios - Xcode 项目构建失败,没有错误

android - Android本地化:适用于所有语言的字符串资源文件

c++ - 寻找翻译应用程序的方法