Problem with NSLocalizedString

I have a problem with my app internazionalization.

I put another lenguage with .string method, I transale it and the app work well, everithings is tramslate but not the sctring of code that I put in

override func viewDidLoad() {

super.viewDidLoad()

// Do any additional setup after loading the view.

Info_TextView.layer.cornerRadius = 5

Info_TextView.text = "Test String"

}


So I try for this string to use the NSLocalizedString:


override func viewDidLoad() {

super.viewDidLoad()


// Do any additional setup after loading the view.

Info_TextView.layer.cornerRadius = 5

Info_TextView.text = NSLocalizedString("Test String", comment: "")

}


and after I put the translate in main.string (localized file)


"Test String" = "Testo di Prova"


Unfortunally this don't work.


Thank you for your time

Replies

You should put this translation in localizable.strings (italian) file, not in the main.strings (italian).

"Test String" = "Testo di Prova";

Note: don't forget ; at the end of each line in .strings files


The format in main.strings is like

"h9C-NM-iCa.text" = "Testo di Prova";


where h9C-NM-iCa is the ID of the object in IB that you see in Identy Inspector (3rd icon with square shape of Inspector panel)


You should also adopt the naming conventions of Swift (camelCase).

For instance, Info_TextView is a var ;

So, it should start with lowercase, and not include underscore

So, writes as

infoTextView