From cf569891f458d6bd00848d2f1ee929c02adecb53 Mon Sep 17 00:00:00 2001 From: Sameer KC Date: Wed, 2 Jan 2019 12:46:40 +0100 Subject: [PATCH 1/3] Type definitions for node-gettext --- node-gettext/index.d.ts | 26 +++++++++++++++++++++++++ node-gettext/node-gettext-tests.ts | 31 ++++++++++++++++++++++++++++++ node-gettext/tsconfig.json | 22 +++++++++++++++++++++ node-gettext/tslint.json | 1 + 4 files changed, 80 insertions(+) create mode 100644 node-gettext/index.d.ts create mode 100644 node-gettext/node-gettext-tests.ts create mode 100644 node-gettext/tsconfig.json create mode 100644 node-gettext/tslint.json diff --git a/node-gettext/index.d.ts b/node-gettext/index.d.ts new file mode 100644 index 0000000000..4d0f760e99 --- /dev/null +++ b/node-gettext/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for node-gettext 2.0 +// Project: http://github.com/alexanderwallin/node-gettext +// Definitions by: Sameer K.C. +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export default 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; +} diff --git a/node-gettext/node-gettext-tests.ts b/node-gettext/node-gettext-tests.ts new file mode 100644 index 0000000000..df01ae82c9 --- /dev/null +++ b/node-gettext/node-gettext-tests.ts @@ -0,0 +1,31 @@ +import Gettext from 'node-gettext'; + +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); diff --git a/node-gettext/tsconfig.json b/node-gettext/tsconfig.json new file mode 100644 index 0000000000..fa6bede617 --- /dev/null +++ b/node-gettext/tsconfig.json @@ -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", + "node-gettext-tests.ts" + ] +} diff --git a/node-gettext/tslint.json b/node-gettext/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/node-gettext/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From f17c61f5c6e5813399d11e68d4fa0df2063e8890 Mon Sep 17 00:00:00 2001 From: Sameer KC Date: Wed, 2 Jan 2019 15:56:33 +0100 Subject: [PATCH 2/3] CommonJS style import No default in npm module --- node-gettext/conf/tslint.json | 1 + node-gettext/index.d.ts | 3 ++- node-gettext/node-gettext-tests.ts | 3 +++ node-gettext/tsconfig.json | 4 +++- 4 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 node-gettext/conf/tslint.json diff --git a/node-gettext/conf/tslint.json b/node-gettext/conf/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/node-gettext/conf/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/node-gettext/index.d.ts b/node-gettext/index.d.ts index 4d0f760e99..735f8db84b 100644 --- a/node-gettext/index.d.ts +++ b/node-gettext/index.d.ts @@ -3,7 +3,8 @@ // Definitions by: Sameer K.C. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export default class GetText { +export = GetText; +declare class GetText { constructor(options?: { debug: boolean; }); addTranslations(locale: string, domain: string, translations: object): void; dgettext(domain: string, msgid: string): string; diff --git a/node-gettext/node-gettext-tests.ts b/node-gettext/node-gettext-tests.ts index df01ae82c9..e20e6aacac 100644 --- a/node-gettext/node-gettext-tests.ts +++ b/node-gettext/node-gettext-tests.ts @@ -1,4 +1,7 @@ +// 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 }); diff --git a/node-gettext/tsconfig.json b/node-gettext/tsconfig.json index fa6bede617..9306d23426 100644 --- a/node-gettext/tsconfig.json +++ b/node-gettext/tsconfig.json @@ -13,7 +13,9 @@ ], "types": [], "noEmit": true, - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true }, "files": [ "index.d.ts", From 26284942785bd43500772a29607fb2b4d6d53904 Mon Sep 17 00:00:00 2001 From: Sameer KC Date: Thu, 3 Jan 2019 10:13:21 +0100 Subject: [PATCH 3/3] Deleting unnecessary file --- node-gettext/conf/tslint.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 node-gettext/conf/tslint.json diff --git a/node-gettext/conf/tslint.json b/node-gettext/conf/tslint.json deleted file mode 100644 index 3db14f85ea..0000000000 --- a/node-gettext/conf/tslint.json +++ /dev/null @@ -1 +0,0 @@ -{ "extends": "dtslint/dt.json" }