- New editor-shell tab (lang): translatable languages as clickable flag tiles (shared langs.js mapping of the 28 Seed-X languages to flags), saved via the settings round-trip; translator service URL(s) shown. - Bootstrap seeds translate_langs with Spanish and Chinese (the original language is never a target). - GET /_api/settings also returns primary_lang. - PageEditor's flag/name helpers move to the shared langs.js.
38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
// Language helpers shared by the editors (the PageEditor language picker,
|
|
// the localization settings tab). Flags come from the country-flag-icons
|
|
// set, same as the analytics visitor cells.
|
|
import * as flagSvgs from 'country-flag-icons/string/3x2'
|
|
|
|
// The Seed-X reference translator's languages (scripts/translator.py) — the
|
|
// translation-target ceiling — each mapped to the country whose flag stands
|
|
// for it (CLDR likely-subtag regions: the country with the most speakers).
|
|
export const TRANSLATABLE = {
|
|
ar: 'EG', cs: 'CZ', da: 'DK', de: 'DE', el: 'GR', en: 'US', es: 'ES',
|
|
fa: 'IR', fi: 'FI', fr: 'FR', hu: 'HU', id: 'ID', it: 'IT', ja: 'JP',
|
|
ko: 'KR', ms: 'MY', nl: 'NL', no: 'NO', pl: 'PL', pt: 'BR', ro: 'RO',
|
|
ru: 'RU', sv: 'SE', th: 'TH', tr: 'TR', uk: 'UA', vi: 'VN', zh: 'CN',
|
|
}
|
|
|
|
const displayNames = new Intl.DisplayNames(['en'], { type: 'language' })
|
|
|
|
// English display name for a language tag ("fi" -> "Finnish").
|
|
export function langName(tag) {
|
|
try {
|
|
return displayNames.of(tag) || tag
|
|
} catch {
|
|
return tag
|
|
}
|
|
}
|
|
|
|
// Flag SVG string for a language tag: the explicit mapping first, then the
|
|
// tag's most likely region (for languages outside the translatable list).
|
|
export function flagFor(tag) {
|
|
const country = TRANSLATABLE[tag]
|
|
if (country) return flagSvgs[country] || ''
|
|
try {
|
|
return flagSvgs[new Intl.Locale(tag).maximize().region] || ''
|
|
} catch {
|
|
return ''
|
|
}
|
|
}
|