td-languages-abbreviations
v1.0.1
Published
TypeScript/JavaScript library with 232 language abbreviations (e.g. en, pl, it). Includes typed constants and language selectors.
Maintainers
Readme
[TusinskiDev] Languages Abbreviations
A TypeScript/JavaScript library providing standardized language abbreviations for 232 languages worldwide. Perfect for internationalization and localization projects.
Features
- ✅ 232 Language Abbreviations: Comprehensive coverage of languages from around the world
- ✅ TypeScript Support: Full type safety with TypeScript definitions
- ✅ Zero Dependencies: Lightweight library with no external dependencies
- ✅ Tree Shaking: Import only what you need
Installation
npm install td-languages-abbreviationsor
yarn add td-languages-abbreviationsUsage
Basic Usage
import Abbreviations from 'td-languages-abbreviations';
// Access individual language abbreviations
console.log(Abbreviations.ENGLISH); // 'en'
console.log(Abbreviations.POLISH); // 'pl'
console.log(Abbreviations.GERMAN); // 'de'Using the Language Array
import { LANGUAGES_ABBREVIATION } from 'td-languages-abbreviations';
// Get all language abbreviations as an array
console.log(LANGUAGES_ABBREVIATION.length); // 232
console.log(LANGUAGES_ABBREVIATION.includes('en')); // trueTypeScript Support
import type { LanguageAbbreviation } from 'td-languages-abbreviations';
function setLanguage(lang: LanguageAbbreviation) {
// TypeScript will ensure only valid language codes are passed
console.log(`Setting language to: ${lang}`);
}
setLanguage('en'); // ✅ Valid
setLanguage('invalid'); // ❌ TypeScript errorAvailable Languages
The library includes abbreviations for languages such as:
- English (
en) - Spanish (
es) - French (
fr) - German (
de) - Chinese (
zh) - Japanese (
ja) - Arabic (
ar) - Russian (
ru) - Portuguese (
pt) - Italian (
it) - And 222 more...
API Reference
Constants
All language abbreviations are available as named constants:
import Abbreviations from 'td-languages-abbreviations';
Abbreviations.ENGLISH // 'en'
Abbreviations.SPANISH // 'es'
Abbreviations.FRENCH // 'fr'
// ... and so onLANGUAGES_ABBREVIATION Array
A readonly array containing all 232 language abbreviations:
import { LANGUAGES_ABBREVIATION } from 'td-languages-abbreviations';
type LanguageAbbreviation = typeof LANGUAGES_ABBREVIATION[number];TypeScript Types
import type { LanguageAbbreviation } from 'td-languages-abbreviations';
// Use for type-safe language handling
interface UserPreferences {
language: LanguageAbbreviation;
fallbackLanguage: LanguageAbbreviation;
}Examples
Language Selector Component
import React from 'react';
import { LANGUAGES_ABBREVIATION } from 'td-languages-abbreviations';
const LanguageSelector: React.FC = () => {
return (
<select>
{LANGUAGES_ABBREVIATION.map(lang => (
<option key={lang} value={lang}>
{lang.toUpperCase()}
</option>
))}
</select>
);
};Validation Function
import type { LanguageAbbreviation } from 'td-languages-abbreviations';
function isValidLanguage(lang: string): lang is LanguageAbbreviation {
return LANGUAGES_ABBREVIATION.includes(lang as LanguageAbbreviation);
}
// Usage
if (isValidLanguage(userInput)) {
// TypeScript knows userInput is a valid LanguageAbbreviation
setUserLanguage(userInput);
}Internationalization Helper
import Abbreviations from 'td-languages-abbreviations';
const SUPPORTED_LANGUAGES = [
Abbreviations.ENGLISH,
Abbreviations.SPANISH,
Abbreviations.FRENCH,
Abbreviations.GERMAN
] as const;
function getLocalizedContent(language: string) {
if (!SUPPORTED_LANGUAGES.includes(language as any)) {
throw new Error(`Unsupported language: ${language}`);
}
// Load localized content...
}Development
Building
npm run buildTesting
npm testLinting
npm run lint
npm run lint:fixFormatting
npm run formatContributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Jarosław Tusiński
