Using spData, I'm able to get the world's country names - but only in English - e.g. Germany, China, Morocco.
I want to get those names in the country's own language - e.g. Deutschland, 中国, المملكة المغربية .
I know I can get their ISO code from spData (DE, CN, MA), but I can't find a package which will convert those to a country name in that country's script.
Packages like countrycode
can convert an ISO code to a country name using countryname("China", destination = 'cldr.short.zh')
- but that requires knowing that the language code for China is zh
.
Is there any way to go from CN → 中国, DE → Deutschland etc?
Using the link suggested by @zx8754 in the comments, you could determine the appropriate destination code and apply it per row. Note that the link uses
zh_hans
while the cldr destination codes usesyue_hans
to specify the language for China, so that had to be manually swapped. This could be simplified, but showing the steps for clarity.