3

Are there any function for converting a language code to language name? For example;

'en' to English,
'ru' to Russian, 'tr' to Turkish

If you help me i will be glad.

3

1 Answer 1

7

You can accomplish this using Intl:

const getLanguage = (code) => { const lang = new Intl.DisplayNames(['en'], {type: 'language'}); return lang.of(code); } const russianLang = getLanguage("ru"); // Russian console.log(russianLang);

You could write a function that receives a code and then use Intl.DisplayNames to get the according language.

Read more about Intl here.

You could rewrite the function in 1 line if you like:

const getL = (c) => new Intl.DisplayNames(['en'], {type: 'language'}).of(c); console.log(getL("ru"));

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.