Wolfram Language

Multilingual Functionality

Sorting Cities and Building a Dictionary

In Version 11, it is possible to sort strings using an alphabetic comparison method defined for each language.

For example, get a group of cities from Denmark.

In[1]:=
Click for copyable input
cityNames = EntityValue[ GeoEntities[ Entity["AdministrativeDivision", {"Nordjylland", "Denmark"}], "City"], "Name"];

Now sort these cities using AlphabeticSort but setting the languages separately to Danish and English, to be able to appreciate the differences between them.

In[2]:=
Click for copyable input
sortedCityNames = Transpose[{AlphabeticSort[cityNames, "Danish"], AlphabeticSort[cityNames, "English"]}];
show complete Wolfram Language input
In[3]:=
Click for copyable input
TextGrid[Join[ Sequence @@ (Prepend[#, {"Danish", "English"}] & /@ Partition[sortedCityNames, UpTo[14]]), 2], Frame -> {None, None, {{{1, 1}, {1, 6}} -> True, {{1, 15}, {1, 6}} -> True, {{1, 15}, {1, 2}} -> True, {{1, 15}, {1, 4}} -> True}}]
Out[3]=

Create a sorted dictionary translating a random sample of words from Swedish to English.

In[4]:=
Click for copyable input
words = AlphabeticSort[ RandomSample[WordList[Language -> "Swedish"], 6], "Swedish"];
In[5]:=
Click for copyable input
sortedTranslations = AlphabeticSort[#, "English"] & /@ WordTranslation[words, "Swedish" -> "English"];
show complete Wolfram Language input
In[6]:=
Click for copyable input
TextGrid[{words, Column /@ sortedTranslations}, Frame -> All]
Out[6]=

Related Examples

de es fr ja ko pt-br ru zh