XCode 本地化字符串 Swift
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26342999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XCode localize string Swift
提问by MatteoAB
I am trying to localize a string list. I have some photos, and for every photo a description of that, and I want to translate the description in another language.
我正在尝试本地化一个字符串列表。我有一些照片,每张照片都有描述,我想用另一种语言翻译描述。
That's the code:
那是代码:
var imageList:[String] = ["new_york_city_sky_house_skyscraper_59212_640x1136.jpg","79506M1pZO4U6d12i0Xzf27765gWo71P5061732uthh68xHQ8Dq1yTQ0Bj8p9F45.jpg","iphone 5 wallpaper new york.jpg","New-York-Vintage-Effect-iphone-5-wallpaper-ilikewallpaper_com.jpg","Superb-View-Over-New-York-iphone-5-wallpaper-ilikewallpaper_com.jpg","New-York-Empire-State-Building-1136x640.jpg","New-York-City-iphone-5s-wallpaper-ilikewallpaper_com.jpg","new-york-city.jpg","New-York-By-Day-iphone-5-wallpaper-ilikewallpaper_com.jpg","The-Empire-State-Building-New-York-1136x640.jpg"]
var nameList:[String] = ["1","2", "3","4","5","6","7","8","9","10"]
var sentMessage: [String] = ["Description here 1", "Description here 2", "Description here 3", "Description here 4", "Description here 5", "Description here 6", "Description here 7", "Description here 8", "Description here 9", "Description here 10"]
I'd like to translate namelist category and sent message category, like this: "Description here 1" in "Descrizione qui 1", "Description here 2" in "Descrizione qui 2"...
我想翻译名单类别和发送的消息类别,如下所示:“Description here 1”中的“Descrizione qui 1”,“Description here 2”中的“Descrizione qui 2”......
What can I do? I am learning by myself to create an app because I have got some ideas, but I am stucked here... Thank you!
我能做什么?我正在自学创建一个应用程序,因为我有一些想法,但我被困在这里......谢谢!
回答by houguet pierre
You can add all localizations in your project info. The file is a key/value
array. After in your code you can call in Objective-C
您可以在项目信息中添加所有本地化。该文件是一个key/value
数组。在你的代码之后,你可以在 Objective-C 中调用
NSLocalizedString(key:tableName:bundle:value:comment:)
like
喜欢
var description = String(format: "%@ %d", arguments: NSLocalizedString("descriptionHere", comment: ""), 2)
Here you can see a swift project with internalisation. http://rshankar.com/internationalization-and-localization-of-apps-in-xcode-6-and-swift/
在这里,您可以看到一个具有内部化功能的 swift 项目。 http://rshankar.com/internationalization-and-localization-of-apps-in-xcode-6-and-swift/