4

We have a country dropdown list in our page.

we have a new requirement to sort the country name based on alphabetical order. But the country name will be populated in different language based on user. If the user is a Japanese user, the country list will be in Japanese language. Will the javascript sort work if the country names are in multi language?

Ian
  • 50,146
  • 13
  • 101
  • 111
user2907217
  • 137
  • 2
  • 13
  • The concept is sorting is know to Japanese and javascript supports this. However as Japanese do not use the alphabet, then Kanji/Hiragana/Katakana can not be expected to be sorted alphabetically – Scary Wombat Dec 04 '13 at 06:17
  • @Scary but sorting by the gojuuon order is possible, but not natively supported sadly :( – ProgrammingLlama Apr 26 '18 at 07:51
  • @john `true` but the OP asks *a new requirement to sort the country name based on alphabetical order* – Scary Wombat Apr 26 '18 at 07:53
  • @Scary True, but I think we can understand that to mean that OP natively speaks a language based on the Latin character set, and that for him that is alphabetical sorting, so that is the terminology he used. So it can be understood that he means "sort the country names according to the sorting norms of the language they are in", no? – ProgrammingLlama Apr 26 '18 at 07:59
  • @john You may be right. Although Japanese sorting of countries is always a mess and sometimes looks like the order is arbitrary ;-) – Scary Wombat Apr 26 '18 at 08:11
  • @Scary That's true. I just took a look at the JP post office's country list and the first 10 are arbitrary, and then the rest are gojuuon order. – ProgrammingLlama Apr 26 '18 at 08:15
  • @Scary Oh, OK. I didn't only skimmed it :) I see what you mean. It's definitely arbitrary. – ProgrammingLlama Apr 26 '18 at 08:25

1 Answers1

2

Assuming Unicode you can try using localeCompare to get it in alphabetical order, (see: https://stackoverflow.com/a/6909444/1059070)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare

Otherwise I believe it will sort according to the unicode character value

Community
  • 1
  • 1
arcyqwerty
  • 10,325
  • 4
  • 47
  • 84