@nextcloud/l10n
Version:
Nextcloud localization and translation helpers for apps and libraries
98 lines (90 loc) • 3.06 kB
TypeScript
/**
* Create a new GettextBuilder instance
*/
export declare function getGettextBuilder(): GettextBuilder;
export declare class GettextBuilder {
private debug;
private language;
private translations;
setLanguage(language: string): this;
/**
* Try to detect locale from context with `en` as fallback value
* This only works within a Nextcloud page context.
*
* @deprecated use `detectLanguage` instead.
*/
detectLocale(): this;
/**
* Try to detect locale from context with `en` as fallback value.
* This only works within a Nextcloud page context.
*/
detectLanguage(): this;
/**
* Register a new translation bundle for a specified language.
*
* Please note that existing translations for that language will be overwritten.
*
* @param language - Language this is the translation for
* @param data - The translation bundle
*/
addTranslation(language: string, data: GettextTranslationBundle): this;
enableDebugMode(): this;
build(): GettextWrapper;
}
export declare interface GettextTranslation {
msgid: string;
msgid_plural?: string;
msgstr: string[];
}
export declare interface GettextTranslationBundle {
headers: {
[headerName: string]: string;
};
translations: {
[context: string]: GettextTranslationContext;
};
}
export declare interface GettextTranslationContext {
[msgid: string]: GettextTranslation;
}
export declare class GettextWrapper {
private bundle;
constructor(pluralFunction: PluralFunction);
/**
* Append new translations to the wrapper.
*
* This is useful if translations should be added on demand,
* e.g. depending on component usage.
*
* @param bundle - The new translation bundle to append
*/
addTranslations(bundle: GettextTranslationBundle): void;
/**
* Get translated string (singular form), optionally with placeholders
*
* @param original original string to translate
* @param placeholders map of placeholder key to value
*/
gettext(original: string, placeholders?: Record<string, string | number>): string;
/**
* Get translated string with plural forms
*
* @param singular Singular text form
* @param plural Plural text form to be used if `count` requires it
* @param count The number to insert into the text
* @param placeholders optional map of placeholder key to value
*/
ngettext(singular: string, plural: string, count: number, placeholders?: Record<string, string | number>): string;
}
/**
* Function for getting plural form index from translated number
*
* @param number Input number to translate
* @return Index of translation plural form
* @example For most languages, like English or German
* ```js
(number:number) => number === 1 ? 0 : 1
```
*/
declare type PluralFunction = (number: number) => number;
export { }