{"name":"prefab-i18n","title":"Localization","kind":"prefab","status":"available","summary":"Localized strings and voice-over from your own bundle: Intl plurals/number/date, per-locale lazy loading, audio fallback chain.","spec":"prefab-i18n@0.1.1","version":"0.1.1","versions":["0.1.1","0.1.0"],"license":"MIT","source":"prototir","sizeKB":3,"requires":[],"permissions":[],"flags":{"wasm":false,"streamed":false},"compatibility":"Desktop and mobile browsers.","install":{"manifest":"{\n  \"modules\": [\n    \"prefab-i18n@0.1.1\"\n  ]\n}","importFrom":"prefab-i18n"},"example":"import { createI18n } from 'prefab-i18n';\n\nconst i18n = await createI18n({\n  locales: ['en', 'it'],\n  fallback: 'en',\n  loadStrings: (locale) => fetch(`locales/${locale}.json`).then((r) => r.json())\n});\n\ntitle.textContent = i18n.t('play');\ncoins.textContent = i18n.t('coins', { count: 3 });","api":[{"heading":"createI18n(options)","entries":[{"signature":"locales = ['en'], fallback = locales[0]","description":"The languages you publish, and the one used when a key is missing."},{"signature":"locale, preferred","description":"Force a starting locale, or pass the player's preference list; otherwise the browser's languages are used."},{"signature":"strings, loadStrings(locale)","description":"Inline tables, or a loader called for one locale at a time. Only the active locale (and the fallback) is ever fetched."},{"signature":"audio: { base, map, locales? }","description":"Voice-over from your bundle at base/locale/file. `locales` narrows it to the languages you recorded."},{"signature":"onChange(locale)","description":"Called after setLocale switches language."}]},{"heading":"The returned i18n","entries":[{"signature":"i18n.t(key, vars)","description":"Translates a key, filling {placeholders}. With vars.count, picks the plural form ({ one, other, ... }) via Intl.PluralRules. A missing key returns the key itself."},{"signature":"i18n.number(value, options), i18n.date(value, options)","description":"Locale-aware formatting through Intl."},{"signature":"await i18n.setLocale(locale)","description":"Switches language, loading its strings on demand."},{"signature":"i18n.locale, i18n.locales, i18n.fallback","description":"The current state."},{"signature":"await i18n.playAudio(key, { volume, loop }), i18n.stopAudio()","description":"Plays a localized clip, falling back to the fallback locale. Returns null when the browser blocks autoplay."},{"signature":"await i18n.preloadAudio(keys?)","description":"Preloads the active locale's clips."},{"signature":"i18n.destroy()","description":"Stops audio and clears caches."}]},{"heading":"Also exported","entries":[{"signature":"negotiateLocale(preferred, available, fallback)","description":"Picks the best available locale for a preference list."}]}],"notes":["Built for the sandbox: a prototype cannot reach translation services, so everything resolves from your own bundle."],"upstreamDocs":null,"labs":[]}