2.1.1 β€’ Published 6 months ago

language-emoji v2.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Language Emoji 🌍

language-emoji is a lightweight and easy-to-use package that helps you transform language codes (e.g., en_US or en) into country emoji flags 🌎, language names, and native language names.

Features ✨

  • 🌍 Supports multiple languages with language codes.
  • πŸ‡ΊπŸ‡Έ Converts language codes to emoji flags.
  • πŸ“ Provides English and native names for languages.
  • ⚑ Lightweight and fast β€” ideal for web and server-side projects, no dependencies.
  • πŸ€– Useful for Telegram bots: parse users language_code easily.

Installation πŸ“¦

Using npm

npm install language-emoji

Using yarn

yarn add language-emoji

Usage πŸš€

Import the package

import { langFlag, fallbackLangFlag, langName, langNativeName } from 'language-emoji';

Example 1: Get Emoji Flag

import { langFlag, fallbackLangFlag } from 'language-emoji';

console.log(langFlag('en_US'));   // Output: πŸ‡ΊπŸ‡Έ
console.log(langFlag('ru'));      // Output: πŸ‡·πŸ‡Ί

console.log(langFlag('lalala'));           // Output: undefined
console.log(fallbackLangFlag('lalala'));   // Output: 🌎

Example 2: Get Language Name

import { langName } from 'language-emoji';

console.log(langName('es'));   // Output: Spanish
console.log(langName('de'));   // Output: German

Example 3: Get Native Language Name

import { langNativeName } from 'language-emoji';

console.log(langNativeName('zh'));   // Output: δΈ­ζ–‡
console.log(langNativeName('ja'));   // Output: ζ—₯本θͺž

API Reference πŸ“š

langData(lang: string): LanguageData | undefined

Returns the language data for a given language code.

  • lang: Language code in formats like en_US or fr.
  • Returns: An object containing:
    • flag: Emoji flag string (e.g., πŸ‡ΊπŸ‡Έ).
    • name: English name string (e.g., English).
    • native_name: Native name string (e.g., FranΓ§ais).

langFlag(lang: string): string | undefined

Returns the emoji flag for a given language code.

  • lang: Language code in formats like en_US or fr.
  • Returns: Emoji flag string (e.g., πŸ‡ΊπŸ‡Έ) or undefined if not found.

fallbackLangFlag(lang: string): string

Returns the emoji flag for a given language code, falling back to 🌍 if not found.

  • lang: Language code.
  • Returns: Emoji flag string (e.g., "πŸ‡ΊπŸ‡Έ") or "🌍" if not found.

langName(lang: string): string

Returns the English name of the language for a given code.

  • lang: Language code.
  • Returns: English name string (e.g., "Spanish") or lang code itself if not found.

langNativeName(lang: string): string

Returns the native name of the language for a given code.

  • lang: Language code.
  • Returns: Native name string (e.g., "FranΓ§ais") or lang code itself if not found.

Supported Languages 🌐

The package supports a wide range of languages. Some examples include:

  • en - English πŸ‡ΊπŸ‡Έ
  • fr - French πŸ‡«πŸ‡·
  • es - Spanish πŸ‡ͺπŸ‡Έ
  • de - German πŸ‡©πŸ‡ͺ
  • zh - Chinese πŸ‡¨πŸ‡³
  • And more...

For the full list of supported languages, check the data object in the source code.

This package supports the following language code formats:

  • IETF BCP 47 - e.g., en-US, fr-CA
  • ISO 639-1 - e.g., en, fr
  • Underscore Format - e.g., en_US, fr_CA (commonly used in localization systems)

You can input any of these formats, and the package will normalize them for consistent handling.


Contributing 🀝

Contributions are welcome! Feel free to open an issue or submit a pull request on GitHub.


License πŸ“„

This project is licensed under the MIT License.


Contact πŸ“¬

For questions or support, reach out via:


Enjoy using language-emoji! 🌍✨

2.1.1

6 months ago

2.1.0

6 months ago

2.0.2

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago