gettext.js definition

This commit is contained in:
Julien CROUZET 2017-02-16 22:19:22 +01:00
parent 3177c01620
commit c66aab0691
4 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,21 @@
import * as Gettext from 'gettext.js';
const json: Gettext.JsonData = {
"": {
"locale": "fr",
"plural-forms": "nplurals=2; plural=n>1;"
},
"Welcome": "Bienvenue",
"There is %1 apple": [
"Il y a %1 pomme",
"Il y a %1 pommes"
]
};
const instance: Gettext.Gettext = Gettext.i18n();
instance.loadJSON(json, 'messages');
instance.setLocale('fr');
if (instance.ngettext('There is %1 apple', 'There are %1 apples', 0) === 'Il y a %1 pomme') {
throw new Error('Failed test');
}

45
gettext.js/index.d.ts vendored Normal file
View File

@ -0,0 +1,45 @@
// Type definitions for gettext.js 0.5
// Project: https://github.com/guillaumepotier/gettext.js
// Definitions by: Julien Crouzet <https://github.com/jucrouzet>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export type PluralForm = (n: number) => number;
export type GettextStatic = (options?: GettextOptions) => Gettext;
export interface GettextOptions {
domain?: string;
locale?: string;
plural_func?: PluralForm;
ctxt_delimiter?: string;
}
export interface JsonDataHeader {
locale: string;
"plural-forms": string;
}
export interface JsonDataMessages {
[key: string]: string | string[] | JsonDataHeader;
}
export interface JsonData extends JsonDataMessages {
"": JsonDataHeader;
}
export interface Gettext {
setMessages: (domain: string, locale: string, messages: JsonDataMessages, plural_forms?: PluralForm) => Gettext;
loadJSON: (jsonData: JsonData, domain?: string) => Gettext;
setLocale: (locale: string) => Gettext;
getLocale: () => string;
textdomain: (domain?: string) => Gettext | string;
gettext: (msgid: string, ...args: any[]) => string;
ngettext: (msgid: string, msgid_plural: string, n: number, ...args: any[]) => string;
pgettext: (msgctxt: string, msgid: string, ...args: any[]) => string;
dcnpgettext: (domain: string, msgctxt: string, msgid: string, msgid_plural: string, n: number, ...args: any[]) => string;
__: (msgid: string, ...args: any[]) => string;
_n: (msgid: string, msgid_plural: string, n: number, ...args: any[]) => string;
_p: (msgctxt: string, msgid: string, ...args: any[]) => string;
}
export const i18n: GettextStatic;

22
gettext.js/tsconfig.json Normal file
View File

@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"gettext.js-tests.ts"
]
}

1
gettext.js/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "../tslint.json" }