fix(bazinga-translator): correct definition to support UMD (#42629)

- correct module definition
- change test to verify CJ/ES6 and global

/cc @anaelChardan

Closes: #34552
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-03-06 23:06:23 +01:00 committed by GitHub
parent 3268c34ad4
commit ab3222235c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 86 additions and 96 deletions

View File

@ -1,99 +1,85 @@
// Type definitions for Translator
// Type definitions for Translator 3.0
// Project: https://github.com/willdurand/BazingaJsTranslationBundle
// Definitions by: Alex <https://github.com/alexndlm>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// 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;

View File

@ -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');

View File

@ -18,6 +18,7 @@
},
"files": [
"index.d.ts",
"bazinga-translator-tests.ts"
"test/bazinga-translator-tests.commonjs.ts",
"test/bazinga-translator-tests.umd.ts"
]
}

View File

@ -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
}
}
{ "extends": "dtslint/dt.json" }