我正在尝试本地化不同语言的数组。
我想要本地化的数组看起来如下:
var watch = ["This watch is blue", "this watch is red", "this watch is white "]
我已经具有本地化的字符串,并且我正在使用方法NSLocalizedString
,但是我不知道如何将数组定位为所有不同的描述。
感谢您的帮助
如果您已经在应用程序中设置了本地化,则仍然可以将NSLocalizedString
用于数组元素而不是直接字符串。
假设您的Localizable.strings
为:
"BlueMessage" = "This watch is blue";
"RedMessage" = "this watch is red";
"WhiteMessage" = "This watch is white ";
然后您可以将watch
数组声明为:
var watch = [NSLocalizedString("BlueMessage", comment: ""),
NSLocalizedString("RedMessage", comment: ""),
NSLocalizedString("WhiteMessage", comment: "")]
它也将是一系列字符串([String]
),包含字符串的本地化版本。