diff --git a/types/bazinga-translator/index.d.ts b/types/bazinga-translator/index.d.ts index a2e9f634ef..e7bb72909d 100644 --- a/types/bazinga-translator/index.d.ts +++ b/types/bazinga-translator/index.d.ts @@ -1,99 +1,85 @@ -// Type definitions for Translator +// Type definitions for Translator 3.0 // Project: https://github.com/willdurand/BazingaJsTranslationBundle // Definitions by: Alex +// Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface BazingaTranslator { - /** - * The current locale. - * - * @type {String} - */ - locale: string; +declare namespace Translator { + interface BazingaTranslator { + /** + * The current locale. + */ + locale: string; - /** - * Fallback locale. - * - * @type {String} - */ - fallback: string; + /** + * Fallback locale. + */ + fallback: string; - /** - * Placeholder prefix. - * - * @type {String} - */ - placeHolderPrefix: string; + /** + * Placeholder prefix. + */ + placeHolderPrefix: string; - /** - * Placeholder suffix. - * - * @type {String} - */ - placeHolderSuffix: string; + /** + * Placeholder suffix. + */ + placeHolderSuffix: string; - /** - * Default domain. - * - * @type {String} - */ - defaultDomain: string; + /** + * Default domain. + */ + defaultDomain: string; - /** - * Plural separator. - * - * @type {String} - */ - pluralSeparator: string; + /** + * Plural separator. + */ + pluralSeparator: string; - /** - * Adds a translation entry. - * - * @param {String} id The message id - * @param {String} message The message to register for the given id - * @param {String} [domain] The domain for the message or null to use the default - * @param {String} [locale] The locale or null to use the default - * - * @return {Object} Translator - */ - add(id: string, message: string, domain?: string, locale?: string): BazingaTranslator; + /** + * Adds a translation entry. + * + * @param id The message id + * @param message The message to register for the given id + * @param domain The domain for the message or null to use the default + * @param locale The locale or null to use the default + */ + add(id: string, message: string, domain?: string, locale?: string): BazingaTranslator; + /** + * Translates the given message. + * + * @param id The message id + * @param parameters An array of parameters for the message + * @param domain The domain for the message or null to guess it + * @param locale The locale or null to use the default + */ + trans(id: string, parameters?: any, domain?: string, locale?: string): string; - /** - * Translates the given message. - * - * @param {String} id The message id - * @param {Object} [parameters] An array of parameters for the message - * @param {String} [domain] The domain for the message or null to guess it - * @param {String} [locale] The locale or null to use the default - * - * @return {String} The translated string - */ - trans(id: string, parameters?: any, domain?: string, locale?: string): string; + /** + * Translates the given choice message by choosing a translation according to a number. + * + * @param id The message id + * @param number The number to use to find the indice of the message + * @param parameters An array of parameters for the message + * @param domain The domain for the message or null to guess it + * @param locale The locale or null to use the default + */ + transChoice(id: string, number: number, parameters?: any, domain?: string, locale?: string): string; - /** - * Translates the given choice message by choosing a translation according to a number. - * - * @param {String} id The message id - * @param {Number} number The number to use to find the indice of the message - * @param {Object} [parameters] An array of parameters for the message - * @param {String} [domain] The domain for the message or null to guess it - * @param {String} [locale] The locale or null to use the default - * - * @return {String} The translated string - */ - transChoice(id: string, number: number, parameters?: any, domain?: string, locale?: string): string, + /** + * Loads translations from JSON. + * + * @param data A JSON string or object literal + */ + fromJSON(data: string): BazingaTranslator; - /** - * Loads translations from JSON. - * - * @param {String} data A JSON string or object literal - * - * @return {Object} Translator - */ - fromJSON(data: string): BazingaTranslator; - - reset(): void; + reset(): void; + } } -declare const Translator: BazingaTranslator; +declare const Translator: Translator.BazingaTranslator; + +export as namespace Translator; + +export = Translator; diff --git a/types/bazinga-translator/test/bazinga-translator-tests.commonjs.ts b/types/bazinga-translator/test/bazinga-translator-tests.commonjs.ts new file mode 100644 index 0000000000..3353e56e28 --- /dev/null +++ b/types/bazinga-translator/test/bazinga-translator-tests.commonjs.ts @@ -0,0 +1,14 @@ +import Translator = require('bazinga-translator'); + +Translator.fallback = 'en'; +Translator.defaultDomain = 'messages'; + +Translator.add('test key', "it work's", 'frontend', 'en'); +Translator.add('test key', 'message with default domain and local'); + +Translator.trans('test key', {}, 'frontend'); +Translator.trans('test key', { foo: 'bar' }, 'DOMAIN_NAME'); +Translator.trans('test key'); + +Translator.transChoice('test key', 1, {}, 'frontend'); +Translator.transChoice('test key', 123, { foo: 'bar' }, 'DOMAIN_NAME'); diff --git a/types/bazinga-translator/bazinga-translator-tests.ts b/types/bazinga-translator/test/bazinga-translator-tests.umd.ts similarity index 100% rename from types/bazinga-translator/bazinga-translator-tests.ts rename to types/bazinga-translator/test/bazinga-translator-tests.umd.ts diff --git a/types/bazinga-translator/tsconfig.json b/types/bazinga-translator/tsconfig.json index c67b26fe03..291937a80a 100644 --- a/types/bazinga-translator/tsconfig.json +++ b/types/bazinga-translator/tsconfig.json @@ -18,6 +18,7 @@ }, "files": [ "index.d.ts", - "bazinga-translator-tests.ts" + "test/bazinga-translator-tests.commonjs.ts", + "test/bazinga-translator-tests.umd.ts" ] } diff --git a/types/bazinga-translator/tslint.json b/types/bazinga-translator/tslint.json index f247515e66..3db14f85ea 100644 --- a/types/bazinga-translator/tslint.json +++ b/types/bazinga-translator/tslint.json @@ -1,12 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "callable-types": false, - "dt-header": false, - "no-consecutive-blank-lines": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "prefer-method-signature": false, - "semicolon": false - } -} \ No newline at end of file +{ "extends": "dtslint/dt.json" }