本地化多个大型plist文件的最佳方法是什么?

时间:2016-03-24 18:46:01

标签: ios objective-c localization plist localizable.strings

在我的应用程序中有很多plist文件,我正在尝试将它们全部本地化。

据我所知,这可以通过简单地(或几乎不)为每个plist创建.strings来完成,并且在每个.strings文件中,您可以使用本地化值正常替换值。

这适用于少量小键的文件。我正在考虑每个超过300个键的plist文件。

因此我决定以.strings格式转换plist,最后将其替换为plist.strings文件。

尝试:

我有一个test.plist,它有400个格式为

的键
  key        type              value
 test1       String            its a string
 test2       Dictionary         
   item1      String            item1 in dictionary test2
   item2      String            item2 in dictionary test2
   item3      String            item3 in dictionary test2
....
....
test100

我通过以编程方式循环遍历每个键并将它们转换为.strings文件格式来提取所有键及其值。

   "value"   :  "value";
   " item1 in dictionary test2":" item1 in dictionary test2";
   " item2 in dictionary test2":" item2 in dictionary test2";
   " item3 in dictionary test2":" item3 in dictionary test2";

Q1:我可以将此内容复制粘贴到InfoPlist.strings中吗?

Q2:我是否需要为test.plist文件创建testPlist.strings?

我知道我们必须为Info.plist文件创建InfoPlist.strings。

但我不确定如果我必须为test.plist文件创建testPlist.strings,或者我可以将已转换的test.plist的内容复制粘贴到InfoPlist.strings中!

这就是我以所需格式获取数据的方式。

    NSString * path = [@"~/test.plist" stringByExpandingTildeInPath];

    NSAssert(path != nil, @"need a path to continue");

    NSDictionary * messagesDictionary = [NSDictionary dictionaryWithContentsOfFile:path];

    NSAssert(messagesDictionary != nil, @"need a dictionary to continue");

    NSMutableString * result_plain = [NSMutableString string];

    for (NSString * messageCode in [[messagesDictionary allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]) {

        NSDictionary * messageInfo = messagesDictionary[messageCode];

        [result_plain appendString:@"\n"];

        if ([messageInfo isKindOfClass:[NSDictionary class]]) {

            [result_plain appendFormat:@"\"%@\" : \"%@\";), ", messageInfo[@"cancel"], messageInfo[@"cancel"]];
            [result_plain appendFormat:@"\"%@\" : \"%@\";), ", messageInfo[@"message"], messageInfo[@"message"]];
            [result_plain appendFormat:@"\"%@\" : \"%@\";), ", messageInfo[@"title"], messageInfo[@"title"]];

       }
        if ([messageInfo isKindOfClass:[NSString class]]) {
            [result_plain appendFormat:@"\"%@\" : \"%@\";), ", messageInfo, messageInfo];
        }
    }

我可以将所有plist字符串(10 + .plist文件字符串)放在InfoPlist.strings文件中吗?

Q3。 xcode是否为所有.plist文件引用了一个plist.strings?

0 个答案:

没有答案