1

I have a 2 localized string files, one for Romanian and one for English. In both files I have this line:

English:

"invalidSum" = "Invalid amount"

Romanian:

"invalidSum" = "Suma invalida"

I use this message in a alert like this:

  let titleAlert = NSLocalizedString("invalidSum", comment: "")

    let sumAlert = UIAlertController(title: titleAlert, message: nil, preferredStyle: .alert)
    sumAlert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
    present(sumAlert, animated: true, completion: nil)
    }

However, whenever the alert shows, I get the message "invalidSum", not "Invalid amount" for english localization and "Suma invalida" for romanian localization. What am I doing wrong?

AndreiVataselu
  • 216
  • 2
  • 16
  • 2
    There should be a semi-colon at the end of each key/value pair in the strings file. – Martin R Nov 19 '17 at 11:11
  • Are you sure that you have setup the Localizable.strings right? are they specified for the desired target(s)? Related: https://stackoverflow.com/questions/35732333/localization-not-working-swift – Ahmad F Nov 19 '17 at 11:13
  • @MartinR I assume that missing a semi-colon should leads to the "The data couldn’t be read because it isn’t in the correct format" compile-time error, at least that's what happening in my case... – Ahmad F Nov 19 '17 at 11:17
  • I added the semi-colon and it's still not working. The strings files were created manually when I picked a new language in Project Info. It created me Main.strings(English) and Main.strings(Romanian). That's where I put my custom alerts messages. – AndreiVataselu Nov 19 '17 at 12:49
  • @AhmadF ok, the localizable.strings were not set ok. going to answer now my question – AndreiVataselu Nov 19 '17 at 13:26

4 Answers4

2

Rename your Localized.string file to Localizable.strings. That's it.

Chathurka
  • 605
  • 6
  • 11
1

Solved it

My issue was that I created those new strings into Main.strings file (The files that Xcode automatically creates for you when you select new languages in Project Info.

I had to create 2 new Strings file called "Localizable.strings" and Localize it one for english, one for romanian. I copied the strings I've written into Main.strings to Localizable.strings and now it works like charm.

AndreiVataselu
  • 216
  • 2
  • 16
1

The name for the localizable file should be "Localizable.strings".

achu
  • 329
  • 3
  • 7
0

In my case, the problem was in an incorrect format. The problem did not arise immediately, but only after the next build cleanup (or tms like that). So, I found that lines from the end of the file are not translated, but from begin are. And I turned out that one of the lines looked like

= "some value";

That is, there simply was no key. And the build was going without errors. But all the lines below were not translated.

dqve
  • 646
  • 6
  • 18