UNPKG

@owja/i18n

Version:

lightweight internationalization library for javascript

62 lines (61 loc) 2.17 kB
import { LanguageOptions, Listener, TranslateOptions, Translations, TranslatorInterface, TranslatorPlugin, Unsubscribe } from "./types"; export declare class Translator implements TranslatorInterface { private readonly _options; private _listener; private _resources; private _registry; private _locale; private _pluralRule; private _pluralRuleFallback; constructor(options?: Partial<LanguageOptions>); /** * Main translate function */ t(key: string, options?: Partial<TranslateOptions>): string; /** * @deprecated use Translator.locale() instead - this will be removed in final release */ language(language?: string): string; /** * Set the locale by language tag or a Intl.Locale object */ locale(locale: string | Intl.Locale): void; /** * Get the short locale which is just the language like "en" * It returns with script if it was set like "uz-Curl" instead of "uz" */ short(): string; /** * Get the region of the locale like "US" from "en-US" */ region(): string | undefined; /** * Get the script of the locale like "Cyrl" from "uz-Cyrl-UZ" */ script(): string | undefined; /** * Get the long locale which is the language and the region like "en-US" * If the locale was set with script, then this will also return the script like "uz-Cyrl-UZ" * * On some systems it may be that region is unset (Debian 10.9) * It also works around unknown/wrong locales like "xx" which can't get maximized */ long(): string; /** * Add translations for a language tag */ addResource(languageTag: string, translations: Translations): void; /** * Add a plugin for a language tag */ addPlugin(plugin: TranslatorPlugin, languageTag?: string): void; /** * Register a listener which will be triggered when: * - translations are added * - plugins are added * - locale get changed */ listen(listener: Listener): Unsubscribe; private _trigger; private _patternFor; }