diff --git a/angular-gettext/angular-gettext-tests.ts b/angular-gettext/angular-gettext-tests.ts index 706fb67fe0..9a10f1062f 100644 --- a/angular-gettext/angular-gettext-tests.ts +++ b/angular-gettext/angular-gettext-tests.ts @@ -1,39 +1,44 @@ /// module angular_gettext_tests { - var gettextCatalog: angular_gettext.gettextCatalog; - + // Configuring angular-gettext // https://angular-gettext.rocketeer.be/dev-guide/configure/ //Setting the language - gettextCatalog.setCurrentLanguage('nl'); + angular.module('myApp').run(function (gettextCatalog: angular.gettext.gettextCatalog) { + gettextCatalog.setCurrentLanguage('nl'); + }); //Highlighting untranslated strings - gettextCatalog.debug = true; + angular.module('myApp').run(function (gettextCatalog: angular.gettext.gettextCatalog) { + gettextCatalog.debug = true; + }); // Marking strings in JavaScript code as translatable. - // https://angular-gettext.rocketeer.be/dev-guide/annotate-js/ - var gettext = angular_gettext.gettext; - var myString = gettext("Hello"); + // https://angular-gettext.rocketeer.be/dev-guide/annotate-js/ + angular.module("myApp").controller("helloController", function (gettext: angular.gettext.gettextFunction) { + var myString = gettext("Hello"); + }); //Translating directly in JavaScript. - angular.module("myApp").controller("helloController", function (gettextCatalog: angular_gettext.gettextCatalog) { + angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { var translated: string = gettextCatalog.getString("Hello"); }); - angular.module("myApp").controller("helloController", function (gettextCatalog: angular_gettext.gettextCatalog) { + angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { var myString2: string = gettextCatalog.getPlural(3, "Bird", "Birds"); }); - var translated: string = gettextCatalog.getString("Hello {{name}}", { name: "Ruben" }); - + angular.module("myApp").controller("helloController", function (gettextCatalog: angular.gettext.gettextCatalog) { + var translated: string = gettextCatalog.getString("Hello {{name}}", { name: "Ruben" }); + }); // Setting strings manually // https://angular-gettext.rocketeer.be/dev-guide/manual-setstrings/ - angular.module("myApp").run(function (gettextCatalog: angular_gettext.gettextCatalog) { + angular.module("myApp").run(function (gettextCatalog: angular.gettext.gettextCatalog) { // Load the strings automatically during initialization. gettextCatalog.setStrings("nl", { "Hello": "Hallo", @@ -47,7 +52,7 @@ module angular_gettext_tests { } // Lazy-loading languages // https://angular-gettext.rocketeer.be/dev-guide/lazy-loading/ - angular.module("myApp").controller("helloController", function ($scope: helloControllerScope, gettextCatalog: angular_gettext.gettextCatalog) { + angular.module("myApp").controller("helloController", function ($scope: helloControllerScope, gettextCatalog: angular.gettext.gettextCatalog) { $scope.switchLanguage = function (lang: string) { gettextCatalog.setCurrentLanguage(lang); gettextCatalog.loadRemote("/languages/" + lang + ".json"); diff --git a/angular-gettext/angular-gettext.d.ts b/angular-gettext/angular-gettext.d.ts index d226801dc4..1a88ef1641 100644 --- a/angular-gettext/angular-gettext.d.ts +++ b/angular-gettext/angular-gettext.d.ts @@ -5,13 +5,13 @@ /// -declare module angular_gettext { +declare module angular.gettext { interface gettextCatalog { - + ////////////// /// Fields /// ////////////// - + /** (default: false): Whether or not to prefix untranslated strings with [MISSING]: or a custom prefix. */ debug: boolean; /** (default: [MISSING]:): Custom prefix for untranslated strings. */ @@ -33,7 +33,7 @@ declare module angular_gettext { /////////////// /// Methods /// /////////////// - + /** Sets the current language and makes sure that all translations get updated correctly. */ setCurrentLanguage(lang: string): void; @@ -41,10 +41,11 @@ declare module angular_gettext { getCurrentLanguage(): string; /** Processes an object of string definitions. More details https://angular-gettext.rocketeer.be/dev-guide/manual-setstrings/ - @param language A language code. - @param strings A dictionary of strings. The format of this dictionary is: - - Keys: Singular English strings (as defined in the source files) - - Values: Either a single string for signular-only strings or an array of plural forms. */ + * @param language A language code. + * @param strings A dictionary of strings. The format of this dictionary is: + * - Keys: Singular English strings (as defined in the source files) + * - Values: Either a single string for signular-only strings or an array of plural forms. + */ setStrings(language: string, strings: { [key: string]: string|string[] }): void; /** Get the correct pluralized (but untranslated) string for the value of n. */ @@ -56,7 +57,7 @@ declare module angular_gettext { * The context parameter is optional: pass null (or don't pass anything) if you're not using it: this skips interpolation and is a lot faster. */ getString(string: string, context?: any): string; - + /** Translate a plural string with the given context. */ getPlural(n: number, string: string, stringPlural: string, context?: any): string; @@ -65,6 +66,8 @@ declare module angular_gettext { } /** If you have text that should be translated in your JavaScript code, wrap it with a call to a function named gettext. This module provides an injectable function to do so */ - function gettext(dummyString: string): string; + interface gettextFunction { + (dummyString: string): string; + } }