0

I'm trying to localize a small Xcode project (Xcode 9 and Swift 4). In that project there are places where I use plurals, so I need to localize them, too. To do that, I use stringsdictfile. In code I use localizedStringWithFormat(_:,fromat,:argument) static method on a String. Here how my code for a plural looks (I just print the words for testing):

 let localizedString = NSLocalizedString("%d apple(s)", comment: "The number of apples")
    print(String.localizedStringWithFormat(localizedString, 0))
    print (String.localizedStringWithFormat(localizedString, 1))
    print(String.localizedStringWithFormat(localizedString, 2))
    print(String.localizedStringWithFormat(localizedString, 10))

Then I create a stringsdict file. It looks like this:

enter image description here

In the video from WWDC 2017 (session 401) about Localization it is said, that when we use stringsdict file for localizing plurals into other languages (in this case, I want to localize it into Russian) we just need to give values for the cases of our development language (English), and when exporting for localization, Xcode will automatically create cases in an XLIFF file for the language into which we want to localize. So I've given values for zero, one and other (in the demo from the session values are given only to keys one and other, however, I don't thing that that's the reason of the problem).

Now, when I create an XLIFF file it looks like this (only the part of apples):

enter image description here

As you can see, Xcode doesn't generate cases for a particular language automatically (for Russian it should have 4). I'm using stringsdict files as well as trying to localize plurals for the first time, so I can't figure out what I'm doing wrong. If you know where is the issue, or have any suggestions, I would appreciate your help.

Tigran Iskandaryan
  • 1,371
  • 2
  • 14
  • 41

1 Answers1

0

There is little you can do in Xcode. XLIFF just holds the segments that it's been told to hold.

A better approach would be to rephrase the strings so that plurals are less an issue, like:

not "%d apple(s)"

but "number of apples: %d"

You should file a bug at apple about that.

Unless you have a requirement to work with the XLIFF from Xcode, I suggest you don't and instead rely on the string files.

brandelune
  • 116
  • 1
  • 7
  • I just wanted plurals to sound less robotic. So, there is nothing wrong with my implementation? – Tigran Iskandaryan Dec 10 '17 at 12:13
  • I don't think there is anything wrong with your implementation. Xcode has not been very good at exporting plurals since the beginning: https://stackoverflow.com/questions/26179269/xcode-6-localization-of-plurals-genders-with-xliff?rq=1 – brandelune Dec 10 '17 at 12:39
  • I've seen in apple dev forum a similar issue about all these. A guy from the company writes that it is a bug and asks others to report about it. Hope in future updates this issue will be solved. Anyway, it is quite sad that this doesn't work, because in the session video it looks very cool and helpful – Tigran Iskandaryan Dec 10 '17 at 13:12
  • Maybe you can ask directly on the apple dev lists? – brandelune Dec 11 '17 at 06:45