使用NSlocalizedstring翻译NSdictionnary数组

时间:2015-05-19 12:46:56

标签: ios arrays swift nsdictionary nslocalizedstring

我有一个像这样的NSdictionary数组

let section1 =
    [NSDictionary(objects: ["English base language test", 2], forKeys: ["title", "value"])
    ]
let section2 =
    [NSDictionary(objects: ["English Base Language test2", 2], forKeys: ["title", "value"])
    ]

(我有更多的对象,但对于这篇文章,我只是在章节中加1) 等等

现在我想本地化我的应用程序,但我只需翻译标题

我已尝试使用NSlocalizedstring,但我无法将其放入此数组

任何想法?

谢谢

1 个答案:

答案 0 :(得分:1)

您可以简单地执行以下操作:

let section1 =
    [NSDictionary(objects: [NSLocalizedString("English base language test", comment:""), 2], forKeys: ["title", "value"])
    ]
let section2 =
    [NSDictionary(objects: [NSLocalizedString("English base language test2", comment:""), 2], forKeys: ["title", "value"])
    ]

并定义两个Localizable.strings文件,一个用于法语,一个用于英语,用这个键:

Localizable.strings(EN)

"English base language test" = "English base language test;
"English base language test2" = "English base language test2";

Localiable.strings(FR)

"English base language test" = "Test d'anglais basique;
"English base language test2" = "Test d'anglais basique 2";