All files / constants language-core.ts

100% Statements 8/8
100% Branches 6/6
100% Functions 3/3
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105                          13x                                   13x             13x                                   13x                                                 22007x 22007x                   13x                   367x    
// SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
 
/**
 * @module Constants/LanguageCore
 * @description Core language data โ€” codes, flags, names, presets, and utility functions.
 *
 * Languages: en, sv, da, no, fi, de, fr, es, nl, ar, he, ja, ko, zh
 */
 
import type { LanguageCode, LanguageMap, LanguagePreset } from '../types/index.js';
 
/** All supported language codes */
export const ALL_LANGUAGES: readonly LanguageCode[] = [
  'en',
  'sv',
  'da',
  'no',
  'fi',
  'de',
  'fr',
  'es',
  'nl',
  'ar',
  'he',
  'ja',
  'ko',
  'zh',
] as const;
 
/** Language presets for quick selection */
export const LANGUAGE_PRESETS: Record<LanguagePreset, readonly LanguageCode[]> = {
  all: ALL_LANGUAGES,
  'eu-core': ['en', 'de', 'fr', 'es', 'nl'],
  nordic: ['en', 'sv', 'da', 'no', 'fi'],
};
 
/** Language flags for display */
export const LANGUAGE_FLAGS: LanguageMap = {
  en: '๐Ÿ‡ฌ๐Ÿ‡ง',
  sv: '๐Ÿ‡ธ๐Ÿ‡ช',
  da: '๐Ÿ‡ฉ๐Ÿ‡ฐ',
  no: '๐Ÿ‡ณ๐Ÿ‡ด',
  fi: '๐Ÿ‡ซ๐Ÿ‡ฎ',
  de: '๐Ÿ‡ฉ๐Ÿ‡ช',
  fr: '๐Ÿ‡ซ๐Ÿ‡ท',
  es: '๐Ÿ‡ช๐Ÿ‡ธ',
  nl: '๐Ÿ‡ณ๐Ÿ‡ฑ',
  ar: '๐Ÿ‡ธ๐Ÿ‡ฆ',
  he: '๐Ÿ‡ฎ๐Ÿ‡ฑ',
  ja: '๐Ÿ‡ฏ๐Ÿ‡ต',
  ko: '๐Ÿ‡ฐ๐Ÿ‡ท',
  zh: '๐Ÿ‡จ๐Ÿ‡ณ',
};
 
/** Native language names */
export const LANGUAGE_NAMES: LanguageMap = {
  en: 'English',
  sv: 'Svenska',
  da: 'Dansk',
  no: 'Norsk',
  fi: 'Suomi',
  de: 'Deutsch',
  fr: 'Franรงais',
  es: 'Espaรฑol',
  nl: 'Nederlands',
  ar: 'ุงู„ุนุฑุจูŠุฉ',
  he: 'ืขื‘ืจื™ืช',
  ja: 'ๆ—ฅๆœฌ่ชž',
  ko: 'ํ•œ๊ตญ์–ด',
  zh: 'ไธญๆ–‡',
};
 
/**
 * Get a language-specific string with English fallback
 *
 * @param map - Language map to look up
 * @param lang - Language code
 * @returns The language-specific value or English fallback
 */
export function getLocalizedString<T>(map: LanguageMap<T>, lang: string): T {
  const code = lang as LanguageCode;
  return map[code] ?? map.en;
}
 
/**
 * Check if a language code is supported
 *
 * @param lang - Language code to check
 * @returns True if the language is supported
 */
export function isSupportedLanguage(lang: string): lang is LanguageCode {
  return ALL_LANGUAGES.includes(lang as LanguageCode);
}
 
/**
 * Determine text direction for a language
 *
 * @param lang - Language code
 * @returns 'rtl' for Arabic/Hebrew, 'ltr' otherwise
 */
export function getTextDirection(lang: string): 'ltr' | 'rtl' {
  return lang === 'ar' || lang === 'he' ? 'rtl' : 'ltr';
}