Zahra Ahmad
ILLUMINATION
Published in
3 min readFeb 23, 2021

--

Automatic Translation of Country Names and Country Codes in R language

Photo by Andrew Stutesman on Unsplash

Why to Translate Country Names?

When working with multilingual websites, you need to convert country names to the language of the interface.

Also, you might want to store or deal with APIs that only understand country codes. Country codes usually are represented in three letters according to the ISO-3166–1-Alpha-3 encoding.

I was working on a multilingual project that deals with country names, we had to translate the country names in the interface to multi-lanauges and keep with each translation the correct country code, so we have consistent data when calling our APIs.

One of my colleague volunteered to do it manually, but I decided to do some research and see if I can do it automatically, and I found a very beautiful library in R language.

Translate Country Names in R

I found a beautiful package in R called countrycode, you can install the package in R as following:

install.packages("countrycode")

For more information about the library you can visit its repository in GitHub here.

Now let’s translate country name from German into Arabic:

--

--

Zahra Ahmad
ILLUMINATION

MSc in Data Science, I love to extract the hell out of any raw data, sexy plots and figures are my coffee