import { DeepKeyOf, DeepPartial, FlattenObjectKeys } from '@maz-ui/utils/ts-helpers'; import { Ref } from 'vue'; import { default as defaultMessages } from './locales/en'; export type TranslationKey = NonNullable>; export type MazUiTranslationsMessages = Record Promise) | (() => Promise<{ default: MazUiTranslationsSchema; }>)>; export interface MazUiTranslationsOptions { /** * The locale to use * @default 'en' */ locale?: string; /** * The fallback locale to use * @default 'en' */ fallbackLocale?: string; /** * Whether to preload the fallback locale asynchronously * @default true */ preloadFallback?: boolean; /** * Modify existing or add new languages */ messages?: MazUiTranslationsMessages; } export interface MazUiTranslationsInstance { /** * The current locale */ locale: Ref; /** * The translation function */ t: (key: TranslationKey, variables?: Record) => string; /** * The function to set the locale dynamically */ setLocale: (locale: string) => Promise; /** * The function to get the available locales */ getAvailableLocales: () => string[]; /** * The function to get the loaded locales */ getLoadedLocales: () => string[]; /** * The function to add messages to a locale */ setLocaleMessage: (locale: string, messages: Partial) => void; /** * The function to check if a locale is loaded */ isLocaleLoaded: (locale: string) => boolean; /** * The function to check if a locale is loading */ isLocaleLoading: (locale: string) => boolean; /** * The function to get the messages */ getMessages: () => Record>; } export type MazUiTranslationsFlattenSchema = Record, string>; export type MazUiTranslationsNestedSchema = typeof defaultMessages; export type MazUiTranslationsSchema = DeepPartial; export interface GlobalState { loadedLocales: Set; messages: Record>; userMessages: MazUiTranslationsMessages; loadingPromises: Map>; }