Merge pull request #31856 from sameercaresu/master

Adding types for node-gettext
This commit is contained in:
Sheetal Nandi
2019-01-03 09:24:39 -08:00
committed by GitHub
4 changed files with 86 additions and 0 deletions

27
node-gettext/index.d.ts vendored Normal file
View File

@@ -0,0 +1,27 @@
// Type definitions for node-gettext 2.0
// Project: http://github.com/alexanderwallin/node-gettext
// Definitions by: Sameer K.C. <https://github.com/sameercaresu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = GetText;
declare class GetText {
constructor(options?: { debug: boolean; });
addTranslations(locale: string, domain: string, translations: object): void;
dgettext(domain: string, msgid: string): string;
dngettext(domain: string, msgid: string, msgidPlural: string, count: number): string;
dnpgettext(domain: string, msgctxt: string, msgid: string, msgidPlural: string, count: number): string;
dpgettext(domain: string, msgctxt: string, msgid: string): string;
emit(eventName: string, eventData: any): void;
getComment(domain: string, msgctxt: string, msgid: string): object | boolean;
gettext(msgid: string): string;
ngettext(msgid: string, msgidPlural: string, count: number): string;
npgettext(msgctxt: string, msgid: string, msgidPlural: string, count: number): string;
off(eventName: string, callback: (params: any) => void): string;
on(eventName: string, callback: (params: any) => void): void;
pgettext(msgctxt: string, msgid: string): string;
setLocale(locale: string): void;
setTextDomain(domain: string): void;
static getLanguageCode(locale: string): string;
textdomain(domain: string): void;
warn(message: string): void;
}

View File

@@ -0,0 +1,34 @@
// with tsc v 2.7 & esModuleInterop & allowSyntheticDefaultImports enabled in tsconfig.json
import Gettext from 'node-gettext';
// or without
// import Gettext = require('node-getttext');
const translations = {};
const gt = new Gettext({ debug: true });
const msgid = 'Get translation';
const msgidPlural = 'Get translations';
const domain = 'domain';
const msgctxt = 'context';
const count = 2;
gt.addTranslations('en-US', 'messages', translations);
gt.setTextDomain(domain);
gt.textdomain(domain);
gt.setLocale('en-US');
gt.gettext(msgid);
gt.dgettext('', msgid);
gt.dngettext(domain, msgid, msgidPlural, count);
gt.dnpgettext(domain, msgctxt, msgid, msgidPlural, count);
gt.dpgettext(domain, msgctxt, msgid);
gt.getComment(domain, msgctxt, msgid);
gt.ngettext(msgid, msgidPlural, count);
gt.npgettext(msgctxt, msgid, msgidPlural, count);
gt.pgettext(msgctxt, msgid);
Gettext.getLanguageCode('en-US');
gt.warn('warning');
const errorListener = (error: string) => {
// do something;
};
gt.on('error', errorListener);
gt.emit('error', 'Error occurred');
gt.off('error', errorListener);

View File

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

1
node-gettext/tslint.json Normal file
View File

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