@j2inn/i18n
Version:
J2 Innovations internationalization library
116 lines (115 loc) • 3.48 kB
TypeScript
import { AntdLocale } from './AntdLocale';
/**
* Cached locale data.
*/
export interface LocaleData {
[prop: string]: string | LocaleData;
}
/**
* Loads, caches and queries localization data.
*/
export declare class I18n {
#private;
/**
* Current locale used by this object.
*/
locale?: string;
/**
* Intl.Locale object for the current locale.
*/
intl?: Intl.Locale;
/**
* Cached locale data for ant design.
*/
antdLocaleData?: AntdLocale;
/**
* The loading flag.
*/
loading: boolean;
constructor(localeData?: LocaleData, antdLocaleData?: AntdLocale, locale?: string | undefined);
/**
* Get a localized string value.
*
* @param key The language key.
* @param values The handlebar values to be substitued.
* @returns The localized string value.
*/
get: (key: string, values?: Record<string, string>) => string;
/**
* Get a localized string value.
*
* ```typescript
* const {t} = useI18n()
* const localizedStr = t('foo.bar')
* ```
*
* @param key The language key.
* @param values The handlebar values to be substitued.
* @returns The localized string value.
*/
t: (key: string, values?: Record<string, string>) => string;
/**
* @returns All the keys used for localization.
*/
keys: () => string[];
/**
* Return true key is available.
*
* @param key The key to test.
* @returns true if the specified key is available.
*/
has: (key: string) => boolean;
/**
* @returns A copy of the internal locale string map.
*/
get internalMap(): Record<string, string>;
/**
* Import the locale data from the server for the given path.
*
* @param locale The language locale to use.
* @param path The path URI.
* @param fetch An optional alternative fetch function to use for
* the network request.
*/
import: (locale: string, path: string, fetchFunc?: typeof fetch) => Promise<void>;
/**
* Replace the values in the string with the supplied values.
*
* The string should use handlebars style syntax to define the
* variables to be replaced. For example, `Hello {{world}} will have
* `world` replaced by an object that has a `world` property.
*
* @param str The string to update.
* @param values The values to be used in the update process.
* @returns The updated string.
*/
static replaceDynamicValues(str: string, values?: Record<string, string>): string;
/**
* Parse a FIN5 language file and return the locale data.
*
* @param input The input text.
* @returns The locale data.
*/
static parseFin5LanguageFile(input: string): LocaleData;
/**
* Extracts the ISO 639-1 langage code from the locale.
*
* @param locale The locale.
* @returns The language code.
*/
static getLanguageCode(locale: string): string;
/**
* Convert the locale to a valid unicode locale identifier.
*
* @param locale The locale tag to convert.
* @returns The language tag.
*/
static toLocaleIdentifier(locale: string): string;
/**
* Convert the locale into an ant design compatible locale provider.
*
* @param locale The locale tag to convert.
* @returns The locale provider.
*/
static toLocaleProvider(locale: string): string;
}