0

I am adding Chinese support to my application.

I have this line that sorts english and other languages

    NSSortDescriptor *sortByItem =  [NSSortDescriptor sortDescriptorWithKey:@"countryName" ascending:YES 
selector:@selector(localizedStandardCompare:)];

But this line appears not to be sorting in Chinese.

How do I modify this line so it will sort in Chinese?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Duck
  • 34,902
  • 47
  • 248
  • 470
  • 1
    What results do you expect, and what results are you getting? – gnasher729 Apr 25 '15 at 19:58
  • I have a list of countries chinese that I want to sort on the fly. Because I don't know chinese I have imported that list on Numbers and sorted that. I am assuming that this list created by Numbers is sorted. Then I use the code above and the lists don't match in order, so I suppose mine is not sorted. – Duck Apr 25 '15 at 20:52
  • 1
    I wouldn't put too much stock in how Numbers sorts those strings. Frankly, I would just trust that `-localizedStandardCompare:` is working sooner than I would trust that Numbers is. The archetype for localized standard sorting is the Finder. Also, the "localized" in the method name refers to the current system language and locale. The sort order of Chinese names when the system language/locale is some variety of English may be different than it would be when the system language/locale is one of the Chinese languages and locales. – Ken Thomases Apr 26 '15 at 02:57

1 Answers1

0

Your assumption that NSSortDescriptor is wrong and Numbers is correct is not a good assumption. It depends on what locale you used in each case (was your iOS device in a Chinese locale? Was your Mac?) Chinese is generally sorted by radical+stroke, but you need a little experience to know how to break characters down into this form. I would frankly trust NSSortDescriptor first in any case. Numbers is hardly the gold standard in such things.

Your best bet if you're working on localizing is to engage a service that specializes in that to help you. If you don't have enough experience in the language to know if you're sorting correctly, then it's hard to imagine getting the rest correct.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610