diff --git a/bazinga-translator/bazinga-translator-tests.ts b/bazinga-translator/bazinga-translator-tests.ts new file mode 100644 index 0000000000..2401641815 --- /dev/null +++ b/bazinga-translator/bazinga-translator-tests.ts @@ -0,0 +1,12 @@ +/// + +Translator.fallback = 'en'; +Translator.defaultDomain = 'messages'; + +Translator.add("test", "it work", "frontend", "en"); + +Translator.trans('key', {}, 'frontend'); +Translator.trans('key', {"foo": "bar"}, 'DOMAIN_NAME'); + +Translator.transChoice('key', 1, {}, 'frontend'); +Translator.transChoice('key', 123, {"foo": "bar"}, 'DOMAIN_NAME'); \ No newline at end of file diff --git a/bazinga-translator/bazinga-translator.d.ts b/bazinga-translator/bazinga-translator.d.ts new file mode 100644 index 0000000000..5467fbfd85 --- /dev/null +++ b/bazinga-translator/bazinga-translator.d.ts @@ -0,0 +1,99 @@ +// Type definitions for Translator +// Project: https://github.com/willdurand/BazingaJsTranslationBundle +// Definitions by: Alex +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface BazingaTranslator { + /** + * The current locale. + * + * @type {String} + */ + locale: string; + + /** + * Fallback locale. + * + * @type {String} + */ + fallback: string; + + /** + * Placeholder prefix. + * + * @type {String} + */ + placeHolderPrefix: string; + + /** + * Placeholder suffix. + * + * @type {String} + */ + placeHolderSuffix: string; + + /** + * Default domain. + * + * @type {String} + */ + defaultDomain: string; + + /** + * Plural separator. + * + * @type {String} + */ + 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; + + + /** + * 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 {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 {String} data A JSON string or object literal + * + * @return {Object} Translator + */ + fromJSON(data: string): BazingaTranslator; + + reset(): void; +} + +declare var Translator: BazingaTranslator; \ No newline at end of file