mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
gettext.js definition
This commit is contained in:
parent
3177c01620
commit
c66aab0691
21
gettext.js/gettext.js-tests.ts
Normal file
21
gettext.js/gettext.js-tests.ts
Normal 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
45
gettext.js/index.d.ts
vendored
Normal 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
22
gettext.js/tsconfig.json
Normal 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
1
gettext.js/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Loading…
Reference in New Issue
Block a user