iOS-将NSDictionary写入Localizable.strings [英] iOS - Writing NSDictionary to Localizable.strings

查看:210
本文介绍了iOS-将NSDictionary写入Localizable.strings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是该问题的连续部分: iOS -我可以在运行时更改localizable.strings内容吗?

This question is continuum to that one: iOS - Could I change the localizable.strings content during runtime?

答案是有用的,但是,我面临一个问题.打印的字符串不包含单个单词键和/或值的引号(如这些").这使Localizable.string无效文件.因此,即使对于格式正确的键/值,也无法从中检索任何内容.

The answer was useful, however, there is a problem that I am facing. The printed string doesn't include quotations (like these "") for single word keys and/or values. This made the Localizable.string invalid file. Hence, nothing is retrieved from it even for keys/values with correct format.

示例:

GBP = GBP; 词汇表=词汇表; "Go_Location" =转到位置";

GBP = GBP; Glossary = Glossary; "Go_Location" = "Go to location";

前两个导致文件成为无效字符串文件.该如何解决?

First two are causing the file to be invalid strings file. How to fix that?

推荐答案

通过枚举字典并将每个键/值对打印到NSString,然后打印到字符串文件来解决该问题.

Solved it by enumerating the dictionary and printing each key/value pair to an NSString, then to the strings file.

这是代码:

__block NSString *languageAndGlossaryDictionary = @"";
[[self getGlossaryDictionary] enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
    languageAndGlossaryDictionary = [languageAndGlossaryDictionary stringByAppendingFormat:@"\n\"%@\" = \"%@\";", key, obj];
}];

这篇关于iOS-将NSDictionary写入Localizable.strings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆