diff --git a/types/y18n/index.d.ts b/types/y18n/index.d.ts new file mode 100644 index 0000000000..ccb02382bf --- /dev/null +++ b/types/y18n/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for y18n 4.0 +// Project: https://github.com/yargs/y18n +// Definitions by: Adam Zerella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +interface Config { + /** + * The locale directory, default ./locales. + */ + directory: string; + /** + * Should newly observed strings be updated in file, default true. + */ + updateFiles: boolean; + /** + * What locale should be used. + */ + locale: string; + /** + * Should fallback to a language-only file (e.g. en.json) be allowed + * if a file matching the locale does not exist (e.g. en_US.json), default true. + */ + fallbackToLanguage: boolean; +} + +declare class Y18N { + /** + * Create an instance of y18n with the config provided + */ + constructor(config?: Config) + + /** + * Print a localized string, %s will be replaced with args. + */ + __(str: string, arg1?: string, arg2?: string, arg3?: string): string; + + /** + * Print a localized string with appropriate pluralization. + * If %d is provided in the string, the count will replace this placeholder. + */ + __n(singularString: string, pluralString: string, count: number, arg1?: string, arg2?: string, arg3?: string): string; + + /** + * Set the current locale being used. + */ + setLocale(str: string): void; + + /** + * What locale is currently being used? + */ + getLocale(): string; + + /** + * Update the current locale with the key value pairs in obj. + */ + updateLocale(obj: object): void; +} + +export = Y18N; diff --git a/types/y18n/tsconfig.json b/types/y18n/tsconfig.json new file mode 100644 index 0000000000..632e88a450 --- /dev/null +++ b/types/y18n/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [ + + ], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "y18n-tests.ts" + ] +} diff --git a/types/y18n/tslint.json b/types/y18n/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/y18n/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file diff --git a/types/y18n/y18n-tests.ts b/types/y18n/y18n-tests.ts new file mode 100644 index 0000000000..39bfd63360 --- /dev/null +++ b/types/y18n/y18n-tests.ts @@ -0,0 +1,21 @@ +import y18n = require("y18n"); + +// Testing custom config +new y18n({ + directory: '../locales', + updateFiles: false, + locale: 'en-AU', + fallbackToLanguage: false +}); + +const Y18N = new y18n(); + +Y18N.__(`my awesome string: foo`); + +Y18N.__n('one fish %s', '%d fishes %s', 2, 'foo'); + +Y18N.setLocale('en-US'); + +Y18N.getLocale(); + +Y18N.updateLocale({});