UNPKG

@uimkit/uikit-react

Version:

<img style="width:64px" src="https://mgmt.uimkit.chat/media/img/avatar.png"/>

185 lines (182 loc) 8.04 kB
import * as i18next from 'i18next'; import { TFunction } from 'i18next'; import Dayjs from 'dayjs'; import moment from 'moment'; import { TDateTimeParser } from '../context/TranslationContext.js'; import { UnknownType } from '../types/index.js'; import enTranslations from './en.js'; type Options = { DateTimeParser?: typeof Dayjs | typeof moment; dayjsLocaleConfigForLanguage?: Partial<ILocale>; debug?: boolean; disableDateTimeTranslations?: boolean; language?: string; logger?: (message?: string) => void; translationsForLanguage?: Partial<typeof enTranslations>; }; declare class Uimi18n { i18nInstance: i18next.i18n; Dayjs: any; setLanguageCallback: (t: TFunction) => void; initialized: boolean; t: TFunction; tDateTimeParser: TDateTimeParser; translations: { [key: string]: { [key: string]: typeof enTranslations | UnknownType; }; }; /** * dayjs.defineLanguage('nl') also changes the global locale. We don't want to do that * when user calls registerTranslation() function. So instead we will store the locale configs * given to registerTranslation() function in `dayjsLocales` object, and register the required locale * with moment, when setLanguage is called. * */ dayjsLocales: { [key: string]: Partial<ILocale>; }; /** * Initialize properties used in constructor */ logger: (msg?: string) => void; currentLanguage: string; DateTimeParser: typeof Dayjs | typeof moment; isCustomDateTimeParser: boolean; i18nextConfig: { debug: boolean; fallbackLng: false; interpolation: { escapeValue: boolean; }; keySeparator: false; lng: string; nsSeparator: false; parseMissingKeyHandler: (key: string) => string; }; /** * Constructor accepts following options: * - language (String) default: 'en' * Language code e.g., en, tr * * - translationsForLanguage (object) * Translations object. Please check src/i18n/en.json for example. * * - disableDateTimeTranslations (boolean) default: false * Disable translations for date-times * * - debug (boolean) default: false * Enable debug mode in internal i18n class * * - logger (function) default: () => {} * Logger function to log warnings/errors from this class * * - dayjsLocaleConfigForLanguage (object) default: 'enConfig' * [Config object](https://momentjs.com/docs/#/i18n/changing-locale/) for internal moment object, * corresponding to language (param) * * - DateTimeParser (function) Moment or Dayjs instance/function. * Make sure to load all the required locales in this Moment or Dayjs instance that you will be provide to Streami18n * * @param {*} options */ constructor(options?: Options); /** * Initializes the i18next instance with configuration (which enables natural language as default keys) */ init(): Promise<{ t: TFunction<"translation", undefined, "translation">; tDateTimeParser: TDateTimeParser; }>; localeExists: (language: string) => boolean; validateCurrentLanguage: () => void; /** Returns an instance of i18next used within this class instance */ geti18Instance: () => i18next.i18n; /** Returns list of available languages. */ getAvailableLanguages: () => string[]; /** Returns all the translation dictionary for all inbuilt-languages */ getTranslations: () => { [key: string]: { [key: string]: UnknownType | { "Commands matching": string; "Emoji matching": string; "Error deleting message": string; "Error: {{ errorMessage }}": string; "People matching": string; "UIChat.\u64A4\u56DE\u4E86\u4E00\u6761\u6D88\u606F": string; "UIConversation.\u6211": string; "You have no contacts currently": string; "You have no conversations currently": string; "default:chat:accounts:fetchAllError": string; "default:chat:accounts:fetchError": string; "default:chat:messages:fetchListError": string; "default:chat:messages:resendError": string; "message.action.copy": string; "message.action.delete": string; "message.action.forward": string; "message.action.quote": string; "message.action.revoke": string; "message.custom.accepted": string; "message.custom.all": string; "message.custom.cancel": string; "message.custom.custom": string; "message.custom.groupCallEnd": string; "message.custom.noResp": string; "message.custom.rejected": string; "message.custom.switchToAudioCall": string; "message.custom.switchToVideoCall": string; "message.custom.talkTime": string; "message.tip.Join in group": string; "message.tip.admin": string; "message.tip.become admin": string; "message.tip.become the new owner": string; "message.tip.by": string; "message.tip.by revoked administrator": string; "message.tip.enable all staff mute": string; "message.tip.kicked out of group": string; "message.tip.member": string; "message.tip.modify group name": string; "message.tip.muted": string; "message.tip.post a new announcement": string; "message.tip.quit group": string; "message.tip.reminder message": string; "message.tip.unmute everyone": string; "message.tip.unmuted": string; "message.tip.\u4F60\u88AB": string; "message.tip.\u4F60\u88AB\u7BA1\u7406\u5458": string; "message.tip.\u4F60\u9000\u51FA\u7FA4\u7EC4": string; "message.tip.\u521B\u5EFA\u7FA4": string; "message.tip.\u540C\u610F\u52A0\u7FA4": string; "message.tip.\u6210\u529F\u52A0\u5165\u7FA4\u7EC4": string; "message.tip.\u62D2\u63A5\u52A0\u7FA4": string; "message.tip.\u64A4\u9500\u7FA4": string; "message.tip.\u7533\u8BF7\u52A0\u5165\u7FA4\u7EC4": string; "message.tip.\u7684\u7BA1\u7406\u5458": string; "message.tip.\u7684\u7BA1\u7406\u5458\u8EAB\u4EFD": string; "message.tip.\u7FA4": string; "message.tip.\u81EA\u5B9A\u4E49\u7FA4\u7CFB\u7EDF\u901A\u77E5": string; "message.tip.\u88AB": string; "message.tip.\u88AB\u62D2\u7EDD": string; "message.tip.\u89E3\u6563": string; "message.tip.\u8BBE\u7F6E\u4E3A\u7FA4": string; "message.tip.\u8E22\u51FA\u7FA4\u7EC4": string; "message.tip.\u9080\u8BF7\u4F60\u52A0\u7FA4": string; "\u65B0\u6D88\u606F!": string; 最新消息: string; 输入消息: string; }; }; }; /** * Returns current version translator function. */ getTranslators(): Promise<{ t: TFunction<"translation", undefined, "translation">; tDateTimeParser: TDateTimeParser; }>; registerTranslation(language: string, translation: typeof enTranslations, customDayjsLocale?: Partial<ILocale>): void; addOrUpdateLocale(key: string, config: Partial<ILocale>): void; setLanguage(language: string): Promise<TFunction<"translation", undefined, "translation">>; registerSetLanguageCallback(callback: (t: TFunction) => void): void; } export { Uimi18n }; //# sourceMappingURL=uimi18n.d.ts.map