gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 08:18:20 25 4
gpt4 key购买 nike

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

意思是,如果我的应用程序有一个字符串 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com