mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
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:
parent
3268c34ad4
commit
ab3222235c
152
types/bazinga-translator/index.d.ts
vendored
152
types/bazinga-translator/index.d.ts
vendored
@ -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;
|
||||
|
||||
@ -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');
|
||||
@ -18,6 +18,7 @@
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"bazinga-translator-tests.ts"
|
||||
"test/bazinga-translator-tests.commonjs.ts",
|
||||
"test/bazinga-translator-tests.umd.ts"
|
||||
]
|
||||
}
|
||||
|
||||
@ -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" }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user