DEV Community

Cover image for How to know which languages are spoken in a country as official or native.
Vic-rider
Vic-rider

Posted on

3

How to know which languages are spoken in a country as official or native.

Made by @Vic-rider

countries-speaking-languages, query country information to know if a language is speaking in this country as official language or a native language.

Install

Install using npm install countries-speaking-languages

Usage

To include Countries-speaking-languages, require or import it:

in JavaScript

CountriesSpeakingLanguage = require('countries-speaking-languages');
Enter fullscreen mode Exit fullscreen mode

in TypeScript

import { CountriesSpeakingLanguage } from "countries-speaking-languages";
Enter fullscreen mode Exit fullscreen mode

Create an instance of it

const countriesSpeakingLanguages = new CountriesSpeakingLanguage();
Enter fullscreen mode Exit fullscreen mode

You can get country information.

Ex :

countriesSpeakingLanguages.getCountry('country_code');
// returns country_datas [object]
Enter fullscreen mode Exit fullscreen mode

You can get country officials languages data.

Ex :

countriesSpeakingLanguages.getCountryOfficialsLanguages('BJ'); // "BJ" as `country_code`
// returns { 'languages' : ['French'], 'languages_codes': ['fr'] }
Enter fullscreen mode Exit fullscreen mode

You can get country spoken languages data.

Ex :

countriesSpeakingLanguages.getCountryAllSpeakingLanguages('BJ'); // "BJ" as `country_code`
// returns [ { "language": "French", "code": "fr" }, { "language": "Yoruba", "code": "yo" }, { "language": "Fon", "code": "fon" } ]
Enter fullscreen mode Exit fullscreen mode

Check if a specific language is spoken as official language in a specific country

Ex :

countriesSpeakingLanguages.hasLanguageAsOfficial('fr', 'JP'); // "JP" as `country_code` and 'fr' as `language_code`
// returns false    : french is not an official language of Japan
Enter fullscreen mode Exit fullscreen mode

Check if a specific language is spoken in a specific country

Ex :

countriesSpeakingLanguages.hasLanguage('pt', 'AO'); // "AO" as `country_code` and 'pt' as `language_code`
// returns true  : portuguese is spoken in Angola
Enter fullscreen mode Exit fullscreen mode

You also have others ways to check if some languages are spoken in a specific country as official languages.

Ex :

countriesSpeakingLanguages.hasEnglishAsOfficialLanguage('AO'); // "AO" as `country_code` `
// returns false  : english is not spoken in Angola as official language
Enter fullscreen mode Exit fullscreen mode

Here is other Official languages checker you can use:

  • hasMadarinAsOfficialLanguage(country_code)
  • hasHindiAsOfficialLanguage(country_code)
  • hasSpanishAsOfficialLanguage(country_code)
  • hasFrenchAsOfficialLanguage(country_code)
  • hasArabicAsOfficialLanguage(country_code)
  • hasBengaliAsOfficialLanguage(country_code)
  • hasRussianAsOfficialLanguage(country_code)
  • hasPortugueseAsOfficialLanguage(country_code)
  • hasIndonesianAsOfficialLanguage(country_code)
  • hasUrduOfficiaAslLanguage(country_code)
  • hasJapaneseAsOfficialLanguage(country_code)
  • hasGermanAsOfficialLanguage(country_code)
  • hasChineseAsOfficialLanguage(country_code)
  • hasTurkishAsOfficialLanguage(country_code)
  • hasKoreanAsOfficialLanguage(country_code)
  • hasYorubaAsOfficialLanguage(country_code)
  • hasFonAsOfficialLanguage(country_code)

Here is the ways to check if some languages are spoken in a specific country.

Ex :

countriesSpeakingLanguages.hasEnglishAsSpeakingLanguages('GH'); // "GH" as `country_code` `
// returns true  : english is spoken in Ghana
Enter fullscreen mode Exit fullscreen mode

Here is other languages checker you can use:

  • hasMadarinAsSpeakingLanguages(country_code)
  • hasHindiAsSpeakingLanguages(country_code)
  • hasSpanishAsSpeakingLanguages(country_code)
  • hasFrenchAsSpeakingLanguages(country_code)
  • hasArabicAsSpeakingLanguages(country_code)
  • hasBengaliAsSpeakingLanguages(country_code)
  • hasRussianAsSpeakingLanguages(country_code)
  • hasPortugueseAsSpeakingLanguages(country_code)
  • hasIndonesianAsSpeakingLanguages(country_code)
  • hasUrduSpeakingLanguage(country_code)
  • hasJapaneseAsSpeakingLanguages(country_code)
  • hasGermanAsSpeakingLanguages(country_code)
  • hasJavaneseAsSpeakingLanguages(country_code)
  • hasChineseAsSpeakingLanguages(country_code)
  • hasTurkishAsSpeakingLanguages(country_code)
  • hasKoreanAsSpeakingLanguages(country_code)
  • hasYorubaAsSpeakingLanguages(country_code)
  • hasFonAsSpeakingLanguages(country_code)

Test

To test countries-speaking-languages, run npm test

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay