Sorting a list of strings with localization in scala

I want to sort a list of strings. I know this is not difficult in scala, but my problem is that I need to sort the lists in different languages. For example, I know that I can sort strings in English very easily. But what about the Russian language or Romanian? What is the best practice for sorting strings in multiple languages ​​in scala? Does the scala collation implement only English letters?

In java, I would do something like this:

Collator coll = Collator.getInstance(locale); coll.setStrength(Collator.PRIMARY) Collections.sort(words, coll); 

I hope someone out there can help me. Thanks in advance Nico.

+7
string sorting scala internationalization localization
source share
1 answer

Nothing special here :). Collator is comparable, so you convert it to Ordering and then use it to sort.

 scala> val ord = Ordering.comparatorToOrdering(Collator.getInstance(Locale.FRENCH)); ord: scala.math.Ordering[Object] = scala.math.LowPriorityOrderingImplicits$$anon$7@759fad4 scala> Seq("deux","Bonsoir","Merci").sorted(ord) res13: Seq[String] = List(Bonsoir, deux, Merci) 
+6
source share

All Articles