@nextcloud/l10n
Version:
Nextcloud localization and translation helpers for apps and libraries
102 lines (92 loc) • 2.81 kB
TypeScript
declare interface AppTranslations {
translations: Translations;
pluralFunction: PluralFunction;
}
/**
* 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;
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(bundle: AppTranslations);
/**
* 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;
/**
* Translation bundle
*
* @example For German translation
* ```json
{
"some": "einige",
"_%n tree_::_%n trees_": [
"%n Baum",
"%n Bäume"
]
}
```
*/
declare type Translations = Record<string, string | string[] | undefined>;
export { }