- Full 8,703-key Hindi dictionary in src/i18n/hi (7 namespace batches),
placeholders verified, only 2% identical strings (brand/protocol names).
- Register hi in Language/LANGUAGE_LOADERS, detectLanguage (hi-IN),
LanguageToggle (🇮🇳, हिन्दी) and dateFnsI18n (hi-IN).
- Lazy-load Noto Sans Devanagari for hi via lib/localeFonts.ts (renamed from
cjkFonts.ts) and add it to the CSS font stack; other locales don't download it.
- check-i18n covers hi: 24 dictionaries / 25 codes at 100%; tsc/tests/build green.
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import type { Language } from '@/contexts/language';
|
|
|
|
const loaded = new Set<Language>();
|
|
|
|
/**
|
|
* Lazy-load the script-specific display font for the active locale (CJK +
|
|
* Devanagari).
|
|
*
|
|
* The Thai (Kanit), Japanese (Noto Sans JP), Korean (Noto Sans KR) and Hindi
|
|
* (Noto Sans Devanagari) font families are large and only needed for users on
|
|
* those locales — but they were imported statically in main.tsx, so every
|
|
* visitor downloaded them. They are now loaded on demand, once per locale, and
|
|
* other users never fetch them. Text briefly falls back to a system font until
|
|
* the stylesheet resolves.
|
|
*/
|
|
export function loadLocaleFont(language: Language): void {
|
|
if (loaded.has(language)) return;
|
|
loaded.add(language);
|
|
|
|
if (language === 'ja') {
|
|
void Promise.all([
|
|
import('@fontsource/noto-sans-jp/400.css'),
|
|
import('@fontsource/noto-sans-jp/500.css'),
|
|
import('@fontsource/noto-sans-jp/700.css'),
|
|
]).catch(() => {});
|
|
} else if (language === 'ko') {
|
|
void Promise.all([
|
|
import('@fontsource/noto-sans-kr/400.css'),
|
|
import('@fontsource/noto-sans-kr/500.css'),
|
|
import('@fontsource/noto-sans-kr/700.css'),
|
|
]).catch(() => {});
|
|
} else if (language === 'th') {
|
|
void Promise.all([
|
|
import('@fontsource/kanit/400.css'),
|
|
import('@fontsource/kanit/500.css'),
|
|
import('@fontsource/kanit/600.css'),
|
|
import('@fontsource/kanit/700.css'),
|
|
]).catch(() => {});
|
|
} else if (language === 'hi') {
|
|
void Promise.all([
|
|
import('@fontsource/noto-sans-devanagari/400.css'),
|
|
import('@fontsource/noto-sans-devanagari/500.css'),
|
|
import('@fontsource/noto-sans-devanagari/700.css'),
|
|
]).catch(() => {});
|
|
}
|
|
}
|