5

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"...

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!

MatteoAB
  • 111
  • 1
  • 3
  • 9

1 Answers1

4

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

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/

Peter Tretyakov
  • 3,380
  • 6
  • 38
  • 54
  • I don't know if I do right. I have changed the sentMessage written before in var sentMessage = String(format: "%@ %d", NSLocalizedString("descriptionHere", comment: "Description here"), 2) But I have got a error: 'NSInteger' is not convertible to 'String.Index' here: @IBAction func showView(){ let vc = SecondViewController(nibName: "SecondViewController", bundle: nil) vc.sentMessage = sentMessage[imageIndex] showViewController(vc, sender: self) What can I do? – MatteoAB Oct 13 '14 at 15:36
  • %@ %@? Tried and it gave me the same error. It's correct to put in "Localizable.string" descriptionHere = "Description here”;? – MatteoAB Oct 13 '14 at 15:51
  • GOOD_MORNING=“Guten Morgen”; like on the url demo. – houguet pierre Oct 13 '14 at 15:54
  • textLabel.text = NSLocalizedString(“GOOD_MORNING”,comment:“Good Morning”) maybe it's your param imageIndex. try without directly textLabel.text = NSLocalizedString(“descriptionHere”,comment:“description here”); – houguet pierre Oct 13 '14 at 15:56
  • are you follow the tutoriel http://rshankar.com/internationalization-and-localization-of-apps-in-xcode-6-and-swift/ ? and download the sample, you will find out, the sample project works fine. – houguet pierre Oct 13 '14 at 16:07
  • Yes I followed it lot of times, it's about two days that I am trying, but I can't applicate it in my project – MatteoAB Oct 13 '14 at 16:11