From 12e1888bd82f9b7c59422e051a08fb589377c8f3 Mon Sep 17 00:00:00 2001 From: newjs Date: Mon, 18 Aug 2014 16:00:44 -0400 Subject: [PATCH 01/29] chore(*): add some steps in contrib on how to checkout based on canary --- CONTRIBUTING.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c94603022..cdcd91535 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -90,7 +90,7 @@ have access to the project`s demos with real XHR operations. Example: `http://localhost:3005/demo/async-loader/index.html` Under the hood, we use a complete [Express](http://expressjs.com/) server stack. You will -find the server configuration at [server.js](server.js) and additional routes for our demos +find the server configuration at [server.js](server.js) and additional routes for our demos at [demo/server_routes.js](demo/server_routes.js). ## Contributing/Submitting changes @@ -98,7 +98,11 @@ at [demo/server_routes.js](demo/server_routes.js). - Checkout a new branch based on canary and name it to what you intend to do: - Example: ```` - $ git checkout -b BRANCH_NAME + $ git checkout -b BRANCH_NAME origin/canary + ```` + If you get error, you may need to fetch canary first by + ```` + $ git remote update && git fetch ```` - Use one branch per fix/feature - Make your changes From 2d8b302d1232e28d3a4e3e2f28518fbbf70a3643 Mon Sep 17 00:00:00 2001 From: knalli Date: Wed, 17 Sep 2014 12:42:28 +0200 Subject: [PATCH 02/29] Bump for next version --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index e5a2b6494..b6fe68599 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,7 @@ "author": "Pascal Precht", "name": "angular-translate", "description": "A translation module for AngularJS", - "version": "2.1.0", + "version": "2.4.0", "homepage": "http://github.com/PascalPrecht/angular-translate", "ignore": [], "repository": { diff --git a/package.json b/package.json index 24642753b..c1571dbcc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-translate", - "version": "2.1.0", + "version": "2.4.0", "description": "A translation module for AngularJS", "main": "index.js", "repository": { From e37d89c3bea44bf9a933596c0fda7a84ee302627 Mon Sep 17 00:00:00 2001 From: Thorsten Spaeth Date: Fri, 9 May 2014 14:22:48 +0200 Subject: [PATCH 03/29] feat(service): introduce `versionInfo` function docs(guide): new versionInfo function chore(grunt): grunt task for version inclusion --- Gruntfile.js | 11 +++++++++++ .../guide/de/03_using-translate-service.ngdoc | 10 ++++++++++ .../guide/en/03_using-translate-service.ngdoc | 10 ++++++++++ package.json | 3 ++- src/service/translate.js | 15 +++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 1c5eefae7..d39796af9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -498,7 +498,17 @@ module.exports = function (grunt) { src: ['docs/content/guide/<%= language %>/*.ngdoc'], title: 'Guide' } + }, + + version: { + options: { + prefix: 'var version\\s+=\\s+[\'"]' + }, + defaults: { + src: ['<%= concat.core.dest %>'] + } } + }); @@ -528,6 +538,7 @@ module.exports = function (grunt) { grunt.registerTask('build:core', [ 'jshint:core', 'concat:core', + 'version', 'ngmin:core', 'concat:banner_core', 'uglify:core' diff --git a/docs/content/guide/de/03_using-translate-service.ngdoc b/docs/content/guide/de/03_using-translate-service.ngdoc index eb5cf81b6..5f73ef4cf 100644 --- a/docs/content/guide/de/03_using-translate-service.ngdoc +++ b/docs/content/guide/de/03_using-translate-service.ngdoc @@ -72,6 +72,16 @@ Dabei muss jedoch beachtet werden, dass der Service immer ein Objekt mit allen Übersetzung (oder sogar alle) nicht übersetzt werden konnten. Eine mögliche Fehlerbehandlung muss von Deiner Seite aus geschehen. +## angular-translate Versionsinformationen +Für einige Anwendungen mag es sinnvoll sein, die eingesetzte Version im "Über uns"-Bereich o.ä. anzuzeigen. +Damit dieses problemlos möglich ist, beinhaltet angular-translate eine Funktion, die sehr einfach verwendet werden +kann und die aktuelle Modulversion zurückgibt: + +
+  $translate.versionInfo();
+  // returns e.g. "2.1.0"
+
+ ## Dinge die berücksichtigt werden sollten Bitte beachte dass `$translate` Service kein Two-Way Data-Binding unterstützt. `$translate` Service arbeitet asynchron, dass bedeteut aber nicht, dass er informiert diff --git a/docs/content/guide/en/03_using-translate-service.ngdoc b/docs/content/guide/en/03_using-translate-service.ngdoc index 084bc67ec..f961663cc 100644 --- a/docs/content/guide/en/03_using-translate-service.ngdoc +++ b/docs/content/guide/en/03_using-translate-service.ngdoc @@ -75,6 +75,16 @@ However, the service will always return an object containing translations -- reg a translation (or even all of them) has failed. When requesting multiple translations in one request, it is up to you to deal with the result. +## angular-translate library version information +As it may be useful for some "About" information in your application, we provide you a convenience +function to display or use the installed library version information. + +Just call it this way: +
+  $translate.versionInfo();
+  // returns e.g. "2.1.0"
+
+ ## Things to keep in mind Please keep in mind that the usage of the `$translate` service doesn't provide a two-way data binding default! `$translate` service works asynchronously, which means diff --git a/package.json b/package.json index c1571dbcc..831193fe8 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "express": "~3.2.4", "grunt-contrib-clean": "~0.5.0", "load-grunt-tasks": "~0.2.0", - "grunt-ngdocs": "~0.1.11" + "grunt-ngdocs": "~0.1.11", + "grunt-version": "~0.3.0" } } diff --git a/src/service/translate.js b/src/service/translate.js index abcc56078..4a6ab72c9 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -32,6 +32,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', $postCompilingEnabled = false, NESTED_OBJECT_DELIMITER = '.'; + var version = 'x.y.z'; // tries to determine the browsers locale var getLocale = function () { @@ -1626,6 +1627,20 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', return result; }; + /** + * @ngdoc function + * @name pascalprecht.translate.$translate#versionInfo + * @methodOf pascalprecht.translate.$translate + * + * @description + * Returns the current version information for the angular-translate library + * + * @return {string} angular-translate version + */ + $translate.versionInfo = function () { + return version; + }; + if ($loaderFactory) { // If at least one async loader is defined and there are no From 666123b90c60d72f07c2111d4d0ad3413a8f8e5c Mon Sep 17 00:00:00 2001 From: newjs Date: Mon, 18 Aug 2014 15:48:19 -0400 Subject: [PATCH 04/29] docs(guide): update chinese docs about versionInfo --- .../zh-cn/03_using-translate-service.ngdoc | 24 +++++++++++++++++++ .../zh-tw/03_using-translate-service.ngdoc | 24 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/docs/content/guide/zh-cn/03_using-translate-service.ngdoc b/docs/content/guide/zh-cn/03_using-translate-service.ngdoc index 0c717a6cf..9c6ab9204 100644 --- a/docs/content/guide/zh-cn/03_using-translate-service.ngdoc +++ b/docs/content/guide/zh-cn/03_using-translate-service.ngdoc @@ -46,6 +46,30 @@ app.controller('Ctrl', ['$scope', '$translate', function ($scope, $translate) { 这就是全部。当你想翻译``的内容时,现在可以在您的控制器内这样做。 +## 多个翻译标识 +翻译服务也意识到一次请求多个翻译的情况。 + +<pre> +app.controller('Ctrl', ['$scope', '$translate', function ($scope, $translate) { + $translate(['HEADLINE', 'PARAGRAPH', 'NAMESPACE.PARAGRAPH']).then(function (translations) { + $scope.headline = translations.HEADLINE; + $scope.paragraph = translations.PARAGRAPH; + $scope.namespaced_paragraph = translations['NAMESPACE.PARAGRAPH']; + }); +}]); +</pre> + +但是,该服务将始终返回一个包含翻译的对象 - 不管翻译(部分或者全部)是否失败了。当在一个要求l里请求多种翻译时,由你来决定如何处理结果。 + +## angular-translate 库版本信息 +因为在您的应用程序中显示“关于”信息是很有用,我们为您提供一个便利的函数来显示,或使用已安装的库版本信息。 + +Just call it this way: +<pre> + $translate.versionInfo(); + // returns e.g. "2.1.0" +</pre> + ## 谨记于心 请记住 `$translate` 翻译服务,不提供默认双向数据绑定! `$translate` 服务以异步方式工作,这意味着 只要其能确定它就返回给定的翻译标识的翻译。如果翻译不存在,它很可能只是返回的翻译标识。 diff --git a/docs/content/guide/zh-tw/03_using-translate-service.ngdoc b/docs/content/guide/zh-tw/03_using-translate-service.ngdoc index c1070cfcf..8015bdd92 100644 --- a/docs/content/guide/zh-tw/03_using-translate-service.ngdoc +++ b/docs/content/guide/zh-tw/03_using-translate-service.ngdoc @@ -46,6 +46,30 @@ $scope.namespaced_paragraph = anotherOne; 這就是全部。當你想翻譯`<TITLE>`的內容時,現在可以在您的控制器內這樣做。 +## 多個翻譯標識 +翻譯服務也意識到一次請求多個翻譯的情況。 + +<pre> +app.controller('Ctrl', ['$scope', '$translate', function ($scope, $translate) { + $translate(['HEADLINE', 'PARAGRAPH', 'NAMESPACE.PARAGRAPH']).then(function (translations) { + $scope.headline = translations.HEADLINE; + $scope.paragraph = translations.PARAGRAPH; + $scope.namespaced_paragraph = translations['NAMESPACE.PARAGRAPH']; + }); +}]); +</pre> + +但是,該服務將始​​終返回一個包含翻譯的對象- 不管翻譯(部分或者全部)是否失敗了。當在一個要求l裡請求多種翻譯時,由你來決定如何處理結果。 +  +## angular-translate 庫版本信息 +因為在您的應用程序中顯示“關於”信息是很有用,我們為​​您提供一個便利的函數來顯示,或使用已安裝的庫版本信息。 + +Just call it this way: +<pre> + $translate.versionInfo(); + // returns e.g. "2.1.0" +</pre> + ## 謹記于心 請記住 `$translate` 翻譯服務,不提供預設雙向資料繫結! `$translate` 服務以非同步方式工作,這意味著 只要其能確定它就返回給定的翻譯標識的翻譯。如果翻譯不存在,它很可能只是返回的翻譯標識。 From e2fb80bbee39cc34fbb0e17f4e743a51e60adfaf Mon Sep 17 00:00:00 2001 From: Max Prichinenko <max.prichinenko@gmail.com> Date: Fri, 29 Aug 2014 00:59:07 +0300 Subject: [PATCH 05/29] docs(guide): update uk/ru docs about versionInfo Paragraph about gaining a version information of the library is translated into Ukrainian and Russian languages. --- docs/content/guide/ru/03_using-translate-service.ngdoc | 10 ++++++++++ docs/content/guide/uk/03_using-translate-service.ngdoc | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/docs/content/guide/ru/03_using-translate-service.ngdoc b/docs/content/guide/ru/03_using-translate-service.ngdoc index 216172bfe..4df96f9d0 100644 --- a/docs/content/guide/ru/03_using-translate-service.ngdoc +++ b/docs/content/guide/ru/03_using-translate-service.ngdoc @@ -72,6 +72,16 @@ app.controller('Ctrl', ['$scope', '$translate', function ($scope, $translate) { (или идентификаторы) не получилось. Запросив несколько переводов за один раз, вы должны сами обработать полученный результат. +## Информация о версии библиотеки angular-translate +Мы предоставляем удобную функцию для получения информации о версии установленной библиотеки, так как +это может быть полезным для какого-нибудь раздела о вашем приложении. + +Просто вызовите её вот так: +<pre> + $translate.versionInfo(); + // returns e.g. "2.1.0" +</pre> + ## Имейте ввиду Пожалуйста, имейте ввиду, что сервис `$translate` по умолчанию не предоставляет двухстороннего связывания данных! Сервис `$translate` работает асинхронно. Это значит, что он возвращает перевод diff --git a/docs/content/guide/uk/03_using-translate-service.ngdoc b/docs/content/guide/uk/03_using-translate-service.ngdoc index a410f9d02..cec2c7243 100644 --- a/docs/content/guide/uk/03_using-translate-service.ngdoc +++ b/docs/content/guide/uk/03_using-translate-service.ngdoc @@ -72,6 +72,16 @@ app.controller('Ctrl', ['$scope', '$translate', function ($scope, $translate) { (або ідентифікатори) не вдалося. Запросивши кілька перекладів за один раз ви повинні самі обробити отриманий результат. +## Інформація про версію бібліотеки angular-translate +Ми надаємо зручну функцію для отримання інформації про версію встановленої бібліотеки, адже це може +бути корисним для якого-небудь розділу про ваш застосунок. + +Просто викличте її ось так: +<pre> + $translate.versionInfo(); + // returns e.g. "2.1.0" +</pre> + ## Майте на увазі Будь ласка, майте на увазі, що сервіс `$translate` за замовчуванням не надає двостороннього From 15831d4dbbf4d62fdfa21075e7a4efca0c12175e Mon Sep 17 00:00:00 2001 From: forresst <forresst@voila.fr> Date: Thu, 19 Jun 2014 17:38:58 +0200 Subject: [PATCH 06/29] docs(guide): update french docs about versionInfo --- docs/content/guide/fr/03_using-translate-service.ngdoc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/content/guide/fr/03_using-translate-service.ngdoc b/docs/content/guide/fr/03_using-translate-service.ngdoc index 6af5c9f27..aa1ecb9ca 100644 --- a/docs/content/guide/fr/03_using-translate-service.ngdoc +++ b/docs/content/guide/fr/03_using-translate-service.ngdoc @@ -74,6 +74,16 @@ Toutefois, le service renverra toujours un objet contenant les traductions - san traduction (ou même toutes) a échoué. Lorsque vous demandez plusieurs traductions en une seule requête, c'est à vous de traiter le résultat. +## Information de la version de la bibliothèque angular-translate +Il peut être utile d'avoir certaines informations dans votre application, nous vous fournissons une +fonction pour afficher ou utiliser les informations de la version de la bibliothèque installée. + +Il suffit de l'appeler de cette façon : +<pre> + $translate.versionInfo(); + // retourne par exemple "2.1.0" +</pre> + ## Les choses à garder à l'esprit Veuillez gardez à l'esprit que l'utilisation du service `$translate` n'assure pas une liaison de données par défaut bidirectionnelle ! Le service `$translate` fonctionne de manière asynchrone, ce qui From 15a7bba1e6dc11f62c7bf1a4be66be01c5fed9bb Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Wed, 17 Sep 2014 13:54:10 +0200 Subject: [PATCH 07/29] docs(service): fix wrong arguments of $translate.instant() Closes #672 --- docs/content/guide/en/21_migration-guide.ngdoc | 2 +- docs/content/guide/fr/21_migration-guide.ngdoc | 2 +- docs/content/guide/ru/21_migration-guide.ngdoc | 2 +- docs/content/guide/uk/21_migration-guide.ngdoc | 2 +- docs/content/guide/zh-cn/21_migration-guide.ngdoc | 2 +- docs/content/guide/zh-tw/21_migration-guide.ngdoc | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/content/guide/en/21_migration-guide.ngdoc b/docs/content/guide/en/21_migration-guide.ngdoc index 14a809d2b..aa0503a1f 100644 --- a/docs/content/guide/en/21_migration-guide.ngdoc +++ b/docs/content/guide/en/21_migration-guide.ngdoc @@ -56,7 +56,7 @@ $translate('translationId').then(function(translation) { ``` If you still want to use the service in sync manner then use -`$translate.instant(langKey, translationId, interpolateParams)` method instead of direct service +`$translate.instant(translationId, interpolateParams, interpolationId)` method instead of direct service call. But note that `instant` method doesn't wait until async loading is done. So, be careful using it. diff --git a/docs/content/guide/fr/21_migration-guide.ngdoc b/docs/content/guide/fr/21_migration-guide.ngdoc index c8886f294..1c32b4a25 100644 --- a/docs/content/guide/fr/21_migration-guide.ngdoc +++ b/docs/content/guide/fr/21_migration-guide.ngdoc @@ -56,7 +56,7 @@ $translate('translationId').then(function(translation) { ``` Si vous voulez continuer à utiliser le service de manière synchrone alors utilisez -la méthode `$translate.instant(langKey, translationId, interpolateParams)` au lieu de l'appel direct +la méthode `$translate.instant(translationId, interpolateParams, interpolationId)` au lieu de l'appel direct du service. Mais notez que la méthode `instant` n'attend pas que le chargement asynchrone soit fait. Alors, soyez prudent dans son utilisation. diff --git a/docs/content/guide/ru/21_migration-guide.ngdoc b/docs/content/guide/ru/21_migration-guide.ngdoc index 73bbb118c..5fc2a8af9 100644 --- a/docs/content/guide/ru/21_migration-guide.ngdoc +++ b/docs/content/guide/ru/21_migration-guide.ngdoc @@ -56,7 +56,7 @@ $translate('translationId').then(function(translation) { ``` Если вы все же хотите использовать сервис в синхронном стиле, используйте метод -`$translate.instant(langKey, translationId, interpolateParams)` вместо прямого вызова сервиса. Но +`$translate.instant(translationId, interpolateParams, interpolationId)` вместо прямого вызова сервиса. Но заметьте, что метод `instant` не ждет завершения асинхронной загрузки. Поэтому, будьте осторожны при его использовании. diff --git a/docs/content/guide/uk/21_migration-guide.ngdoc b/docs/content/guide/uk/21_migration-guide.ngdoc index 86ec85090..e66ac6207 100644 --- a/docs/content/guide/uk/21_migration-guide.ngdoc +++ b/docs/content/guide/uk/21_migration-guide.ngdoc @@ -56,7 +56,7 @@ $translate('translationId').then(function(translation) { ``` Якщо ви, все ж таки, хочете використовувати сервіс у синхронному стилі, використовуйте метод -`$translate.instant(langKey, translationId, interpolateParams)` замість прямого виклику сервісу. Але +`$translate.instant(translationId, interpolateParams, interpolationId)` замість прямого виклику сервісу. Але майте на увазі, що метод `instant` не чекає завершення асинхронного завантаження. Тому, будьте обережні при його використанні. diff --git a/docs/content/guide/zh-cn/21_migration-guide.ngdoc b/docs/content/guide/zh-cn/21_migration-guide.ngdoc index 7cf85bba5..ae3cc8e21 100644 --- a/docs/content/guide/zh-cn/21_migration-guide.ngdoc +++ b/docs/content/guide/zh-cn/21_migration-guide.ngdoc @@ -51,7 +51,7 @@ $translate('translationId').then(function(translation) { ``` 如果您仍然想同步的方式使用该服务,那么请使用 -`$translate.instant(langKey, translationId, interpolateParams)` 方法,而不是直接的服务通话。 +`$translate.instant(translationId, interpolateParams, interpolationId)` 方法,而不是直接的服务通话。 但是请注意, `instant` 方法不会等到异步加载完成。因此,要小心使用它。 ## 事件现在只在$rootScope发射 diff --git a/docs/content/guide/zh-tw/21_migration-guide.ngdoc b/docs/content/guide/zh-tw/21_migration-guide.ngdoc index fb39f19b2..4202a16cd 100644 --- a/docs/content/guide/zh-tw/21_migration-guide.ngdoc +++ b/docs/content/guide/zh-tw/21_migration-guide.ngdoc @@ -51,7 +51,7 @@ stringFromService = translationId; ``` 如果您仍然想同步的方式使用該服務,那麼請使用 -`$translate.instant(langKey, translationId, interpolateParams)` 方法,而不是直接的服務通話。 +`$translate.instant(translationId, interpolateParams, interpolationId)` 方法,而不是直接的服務通話。 但是請注意, `instant` 方法不會等到非同步載入完成。因此,要小心使用它。 ## 事件現在只在$rootScope發射 From 50474dc085d2512103484552b0d30400ed06350a Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Sun, 7 Sep 2014 18:29:11 +0200 Subject: [PATCH 08/29] Rework .gitignore --- .gitignore | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 6ceb7a0e5..cbaabf3bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,18 @@ +/node_modules/ +/components/ +/bower_components/ +/test_scopes/angular_1.3/bower_components/ +/dist/ +/demo/js/angular-translate-latest.js + +# OS X .DS_Store -node_modules -components -bower_components -dist -demo/js/angular-translate-latest.js -.idea + +# IntelliJ stuff +/.idea/ *.iml -atlassian-ide-plugin.xml \ No newline at end of file +# Eclipse (plugins) +/atlassian-ide-plugin.xml + +# Auto-added patterns + From 99f74aa513ee0f4aa3f8d322bd238a4cbbf778df Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Mon, 8 Sep 2014 15:48:39 +0200 Subject: [PATCH 09/29] Add silence to global dependency installing --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9195c0054..ba3672bb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ node_js: - "0.10" before_install: - - npm install -g grunt-cli karma-cli + - npm install -qg grunt-cli karma-cli before_script: - export DISPLAY=:99.0 From 8bf49d0cb30b43a274dc56305d3db87d185de24c Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Sun, 7 Sep 2014 18:32:35 +0200 Subject: [PATCH 10/29] Reduce the resources of a published npm release --- .npmignore | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..8f92424c3 --- /dev/null +++ b/.npmignore @@ -0,0 +1,22 @@ +/bower_components/ +/demo/ +/docs/ +/identity/ +/src/ +/test/ +/.bowerrc +/.editorconfig +/.jshintrc +/.travis.yml +/bower.json +/CONTRIBUTING.md +/*.sh +/*.js +/*.png +/update-docs + +# IntelliJ stuff +.idea +*.iml +# Eclipse (plugins) +/atlassian-ide-plugin.xml From 4b9906e0ab2dbc1f4ae01a2c225966946aa063a3 Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Sun, 7 Sep 2014 18:42:37 +0200 Subject: [PATCH 11/29] Let point npm's main file to generated artifact --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 831193fe8..ad6120798 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "angular-translate", "version": "2.4.0", "description": "A translation module for AngularJS", - "main": "index.js", + "main": "dist/angular-translate.js", "repository": { "type": "git", "url": "http://github.com/angular-translate/angular-translate" From 0fad92c558e36013d33ccd87b0041c123faf3a24 Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Sun, 7 Sep 2014 18:36:40 +0200 Subject: [PATCH 12/29] Introduce npm user script `shipit` Ensure all bower resources are up to date and creating all release files. Introduce new grunt task `pre-release` `release` behaves just as `build` except running only headless tests. --- Gruntfile.js | 10 ++++++++++ package.json | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index d39796af9..23e052a45 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -522,9 +522,19 @@ module.exports = function (grunt) { grunt.registerTask('test-browser-firefox', ['karma:browser-firefox-unit', 'karma:browser-firefox-midway']); grunt.registerTask('test-all', ['karma']); + grunt.registerTask('prepare-release', [ + 'jshint:all', + 'test-headless', + 'build-all' + ]); + grunt.registerTask('build', [ 'jshint:all', 'karma', + 'build-all' + ]); + + grunt.registerTask('build-all', [ 'build:core', 'build:messageformat_interpolation', 'build:handler_log', diff --git a/package.json b/package.json index ad6120798..138b2aace 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,9 @@ "url": "http://github.com/angular-translate/angular-translate" }, "scripts": { - "postinstall": "bower install", - "test": "karma start karma.unit.conf.js --single-run" + "prepublish": "bower install", + "shipit": "bower install && bower update && grunt prepare-release", + "test": "grunt test" }, "author": { "name": "Pascal Precht" From ac2f35c9a9aa0c319859cb57b59a8113e67f7e9a Mon Sep 17 00:00:00 2001 From: Thorsten Spaeth <info@conserata.com> Date: Tue, 26 Aug 2014 18:33:19 +0200 Subject: [PATCH 13/29] fix(service): correctly iterate in fallback languages (fixes #690) --- src/service/translate.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index 4a6ab72c9..d3ebf4c2b 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -804,9 +804,13 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', // maybe the language from storage is also defined as fallback language // we increase the fallback language index to not search in that language // as fallback, since it's probably the first used language - fallbackIndex = (index > -1) ? index+=1 : 0; + // in that case the index starts after the first element + fallbackIndex = (index === 0) ? 1 : 0; + // but we can make sure to ALWAYS fallback to preferred language at least - $fallbackLanguage.push($preferredLanguage); + if (indexOf($fallbackLanguage, $preferredLanguage) < 0) { + $fallbackLanguage.push($preferredLanguage); + } } } return promise; From ec84a7b7bb76dc6a885b21d2de6294eda4db979e Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Wed, 17 Sep 2014 14:51:55 +0200 Subject: [PATCH 14/29] chore(tests): avoid running debug tests in task `test-all` --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 23e052a45..b61bc3042 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -520,7 +520,7 @@ module.exports = function (grunt) { // Advanced test tasks grunt.registerTask('test-headless', ['karma:headless-unit', 'karma:headless-midway']); grunt.registerTask('test-browser-firefox', ['karma:browser-firefox-unit', 'karma:browser-firefox-midway']); - grunt.registerTask('test-all', ['karma']); + grunt.registerTask('test-all', ['test', 'test-headless', 'test-browser-firefox']); grunt.registerTask('prepare-release', [ 'jshint:all', From 2204f4ffa1ad8272f4368f5248cd12625875510d Mon Sep 17 00:00:00 2001 From: wongkwl <keith.wong@objectvalley.com> Date: Thu, 18 Sep 2014 15:35:03 +0800 Subject: [PATCH 15/29] feat(service): prefer detecting language by `navigator.languages` #722 --- src/service/translate.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/service/translate.js b/src/service/translate.js index d3ebf4c2b..1db1bd977 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -38,6 +38,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', var getLocale = function () { var nav = window.navigator; return (( + angular.isArray(nav.languages) ? nav.languages[0] : nav.language || nav.browserLanguage || nav.systemLanguage || From bffbf04350f2f4eb7f60018d133f7ccfb3dd2f4c Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Wed, 17 Sep 2014 13:05:48 +0200 Subject: [PATCH 16/29] fix(filter): mark filter being stateful required since Angular 1.3 rc2 --- src/filter/translate.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/filter/translate.js b/src/filter/translate.js index e2966ab6d..602d31f5a 100644 --- a/src/filter/translate.js +++ b/src/filter/translate.js @@ -50,7 +50,7 @@ angular.module('pascalprecht.translate') </example> */ .filter('translate', ['$parse', '$translate', function ($parse, $translate) { - return function (translationId, interpolateParams, interpolation) { + var translateFilter = function (translationId, interpolateParams, interpolation) { if (!angular.isObject(interpolateParams)) { interpolateParams = $parse(interpolateParams)(this); @@ -58,4 +58,10 @@ angular.module('pascalprecht.translate') return $translate.instant(translationId, interpolateParams, interpolation); }; + + // Since AngularJS 1.3, filters which are not stateless (depending at the scope) + // have to explicit define this behavior. + translateFilter.$stateful = true; + + return translateFilter; }]); From 94653187b81497d1d4e04dfa17abdabfd6e0e73b Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 15:54:58 +0200 Subject: [PATCH 17/29] fix(filter): interpolated params w/ scope aren't possible starting AJS1.3 BREAKING CHANGE: Since filters are stateless and have no access to its scope anymore (see https://github.com/angular/angular.js/commit/8863b9d04c722b278fa93c5d66ad1e578ad6eb1f), a context must be given explicitly. This removes the feature of an interpolation based on the scope (context), even without the $rootScope. However, the feature will still work in AJS <=1.2, so we won't remove it completely yet. Handle the feature as slightly deprecated. --- test/unit/filter/translate.spec.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/test/unit/filter/translate.spec.js b/test/unit/filter/translate.spec.js index c7c10cc42..73d7a8eba 100644 --- a/test/unit/filter/translate.spec.js +++ b/test/unit/filter/translate.spec.js @@ -84,11 +84,22 @@ describe('pascalprecht.translate', function () { expect(value[6]).toEqual('55'); }); - it('should replace interpolate directive on element with given values', function () { - var element = $compile(angular.element('<div>{{"TRANSLATION_ID" | translate: "{value: foo}"}}</div>'))($rootScope); - $rootScope.$digest(); - expect(element.html()).toEqual('Lorem Ipsum bar'); - }); + if (angular.version.major === 1 && angular.version.minor <= 2) { + // Until and including AJS 1.2, a filter was bound to a context (current scope). This was removed in AJS 1.3 + it('should replace interpolate directive on element with given values', function () { + var element = $compile(angular.element('<div>{{"TRANSLATION_ID" | translate: "{value: foo}"}}</div>'))($rootScope); + $rootScope.$digest(); + expect(element.html()).toEqual('Lorem Ipsum bar'); + }); + } else { + it('should replace interpolate directive on element with given values', function () { + $rootScope['__this'] = {value: 'bar'}; + var element = $compile(angular.element('<div>{{"TRANSLATION_ID" | translate: __this}}</div>'))($rootScope); + $rootScope.$digest(); + expect(element.html()).toEqual('Lorem Ipsum bar'); + $rootScope['__this'] = undefined; + }); + } }); describe('additional interpolation', function () { From 73b289d18f080b0784c331406843e685b56db07c Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 16:07:54 +0200 Subject: [PATCH 18/29] feat(service): enrich events with the currently handled language key --- src/service/translate.js | 26 +++++++++++++------------- test/unit/service/translate.spec.js | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index 1db1bd977..28f877d3c 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -867,7 +867,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', */ var useLanguage = function (key) { $uses = key; - $rootScope.$emit('$translateChangeSuccess'); + $rootScope.$emit('$translateChangeSuccess', {language: key}); if ($storageFactory) { Storage.set($translate.storageKey(), $uses); @@ -878,7 +878,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', angular.forEach(interpolatorHashMap, function (interpolator, id) { interpolatorHashMap[id].setLocale($uses); }); - $rootScope.$emit('$translateChangeEnd'); + $rootScope.$emit('$translateChangeEnd', {language: key}); }; /** @@ -900,14 +900,14 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', var deferred = $q.defer(); - $rootScope.$emit('$translateLoadingStart'); + $rootScope.$emit('$translateLoadingStart', {language: key}); pendingLoader = true; $injector.get($loaderFactory)(angular.extend($loaderOptions, { key: key })).then(function (data) { var translationTable = {}; - $rootScope.$emit('$translateLoadingSuccess'); + $rootScope.$emit('$translateLoadingSuccess', {language: key}); if (angular.isArray(data)) { angular.forEach(data, function (table) { @@ -921,11 +921,11 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', key: key, table: translationTable }); - $rootScope.$emit('$translateLoadingEnd'); + $rootScope.$emit('$translateLoadingEnd', {language: key}); }, function (key) { - $rootScope.$emit('$translateLoadingError'); + $rootScope.$emit('$translateLoadingError', {language: key}); deferred.reject(key); - $rootScope.$emit('$translateLoadingEnd'); + $rootScope.$emit('$translateLoadingEnd', {language: key}); }); return deferred.promise; }; @@ -1398,7 +1398,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', var deferred = $q.defer(); - $rootScope.$emit('$translateChangeStart'); + $rootScope.$emit('$translateChangeStart', {language: key}); // Try to get the aliased language key var aliasedKey = negotiateLocale(key); @@ -1420,9 +1420,9 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', } }, function (key) { $nextLang = undefined; - $rootScope.$emit('$translateChangeError'); + $rootScope.$emit('$translateChangeError', {language: key}); deferred.reject(key); - $rootScope.$emit('$translateChangeEnd'); + $rootScope.$emit('$translateChangeEnd', {language: key}); }); } else { deferred.resolve(key); @@ -1498,15 +1498,15 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', function resolve() { deferred.resolve(); - $rootScope.$emit('$translateRefreshEnd'); + $rootScope.$emit('$translateRefreshEnd', {language: langKey}); } function reject() { deferred.reject(); - $rootScope.$emit('$translateRefreshEnd'); + $rootScope.$emit('$translateRefreshEnd', {language: langKey}); } - $rootScope.$emit('$translateRefreshStart'); + $rootScope.$emit('$translateRefreshStart', {language: langKey}); if (!langKey) { // if there's no language key specified we refresh ALL THE THINGS! diff --git a/test/unit/service/translate.spec.js b/test/unit/service/translate.spec.js index 222572de7..5c27ac3f7 100644 --- a/test/unit/service/translate.spec.js +++ b/test/unit/service/translate.spec.js @@ -1342,21 +1342,21 @@ describe('pascalprecht.translate', function () { spyOn($rootScope, '$emit'); $translate.refresh(); $timeout.flush(); - expect($rootScope.$emit).toHaveBeenCalledWith('$translateRefreshStart'); + expect($rootScope.$emit).toHaveBeenCalledWith('$translateRefreshStart', {language: undefined}); }); it('should emit $translateRefreshEnd', function () { spyOn($rootScope, '$emit'); $translate.refresh(); $timeout.flush(); - expect($rootScope.$emit).toHaveBeenCalledWith('$translateRefreshEnd'); + expect($rootScope.$emit).toHaveBeenCalledWith('$translateRefreshEnd', {language: undefined}); }); it('should emit $translateChangeSuccess event', function() { spyOn($rootScope, '$emit'); $translate.refresh(); $timeout.flush(); - expect($rootScope.$emit).toHaveBeenCalledWith('$translateChangeSuccess'); + expect($rootScope.$emit).toHaveBeenCalledWith('$translateChangeSuccess', {language: 'en_EN'}); }); }); }); From b68560160ea51b07030b0cc0ebc4ece440546ad0 Mon Sep 17 00:00:00 2001 From: tamtakoe <tamtakoe@gmail.com> Date: Fri, 25 Apr 2014 19:52:43 +0400 Subject: [PATCH 19/29] feat(loaders): introduce loader cache It useful if we disable cache for dynamic content, but want enable it for translation files (static content). Also it useful if we need include translation into build file (cache in advance for production). ```js app.run(function($translationCache) { $translationCache.put('/compiled/module1/locals/en.json', '{"MODULE1.HELLO":"Hi!"}'); // Other translations string added by Grunt }); ``` feat(cache): introduce customizable loader cache * `$translationCache` is fully flexible a string (name of an instance) or an instance itself * `$translationCache` could be `true` for an AJS internal default New feature usage: ```js $translateProvider.useLoaderCache(false) // disable any cache (default behaviour) $translateProvider.useLoaderCache(true) // use `$http({cache: true}) $translateProvider.useLoaderCache() // use our internal default `$translationCache` (actually `$translateProvider.useLoaderCache('$translationCache')` $translateProvider.useLoaderCache('cacheService') // use the given identifying cacheService $translateProvider.useLoaderCache(cacheService) // use the cacheService ``` This also introduces the feature loaders are provided with the option `$http` for additional standard params. Currently, only `$http.cache` could be defined. Closes #529 --- src/service/loader-partial.js | 27 +++++--- src/service/loader-static-files.js | 4 +- src/service/loader-url.js | 4 +- src/service/translate.js | 62 ++++++++++++++++++- src/service/translationCache.js | 15 +++++ test/unit/service/loader-partial.spec.js | 25 ++++++++ test/unit/service/loader-static-files.spec.js | 17 ++++- test/unit/service/loader-url.spec.js | 16 ++++- 8 files changed, 154 insertions(+), 16 deletions(-) create mode 100644 src/service/translationCache.js diff --git a/src/service/loader-partial.js b/src/service/loader-partial.js index 5c5f13521..731e35626 100644 --- a/src/service/loader-partial.js +++ b/src/service/loader-partial.js @@ -40,16 +40,16 @@ angular.module('pascalprecht.translate') return urlTemplate.replace(/\{part\}/g, this.name).replace(/\{lang\}/g, targetLang); }; - Part.prototype.getTable = function(lang, $q, $http, urlTemplate, errorHandler) { + Part.prototype.getTable = function(lang, $q, $http, $httpOptions, urlTemplate, errorHandler) { var deferred = $q.defer(); if (!this.tables[lang]) { var self = this; - $http({ + $http(angular.extend({}, $httpOptions, { method : 'GET', - url : this.parseUrl(urlTemplate, lang) - }).success(function(data){ + url: this.parseUrl(urlTemplate, lang) + })).success(function(data){ self.tables[lang] = data; deferred.resolve(data); }).error(function() { @@ -226,6 +226,7 @@ angular.module('pascalprecht.translate') * @requires $http * @requires $injector * @requires $rootScope + * @requires $translate * * @description * @@ -233,8 +234,8 @@ angular.module('pascalprecht.translate') * * @throws {TypeError} */ - this.$get = ['$rootScope', '$injector', '$q', '$http', - function($rootScope, $injector, $q, $http) { + this.$get = ['$rootScope', '$injector', '$q', '$http', '$translate', + function($rootScope, $injector, $q, $http, $translate) { /** * @ngdoc event @@ -278,9 +279,10 @@ angular.module('pascalprecht.translate') if (hasPart(part) && parts[part].isActive) { loaders.push( parts[part] - .getTable(options.key, $q, $http, options.urlTemplate, errorHandler) + .getTable(options.key, $q, $http, options.$http, options.urlTemplate, errorHandler) .then(addTablePart) ); + parts[part].urlTemplate = options.urlTemplate; } } @@ -386,6 +388,17 @@ angular.module('pascalprecht.translate') if (hasPart(name)) { var wasActive = parts[name].isActive; if (removeData) { + var cache = $translate.loaderCache(); + if (typeof(cache) === 'string') { + // getting on-demand instance of loader + cache = $injector.get(cache); + } + // Purging items from cache... + if (typeof(cache) === 'object') { + angular.forEach(parts[name].tables, function(value, key) { + cache.remove(parts[name].parseUrl(parts[name].urlTemplate, key)); + }); + } delete parts[name]; } else { parts[name].isActive = false; diff --git a/src/service/loader-static-files.js b/src/service/loader-static-files.js index 720d33657..de6b8f6c4 100644 --- a/src/service/loader-static-files.js +++ b/src/service/loader-static-files.js @@ -22,7 +22,7 @@ angular.module('pascalprecht.translate') var deferred = $q.defer(); - $http({ + $http(angular.extend({}, options.$http, { url: [ options.prefix, options.key, @@ -30,7 +30,7 @@ angular.module('pascalprecht.translate') ].join(''), method: 'GET', params: '' - }).success(function (data) { + })).success(function (data) { deferred.resolve(data); }).error(function (data) { deferred.reject(options.key); diff --git a/src/service/loader-url.js b/src/service/loader-url.js index 30f29513e..759a1e069 100644 --- a/src/service/loader-url.js +++ b/src/service/loader-url.js @@ -24,11 +24,11 @@ angular.module('pascalprecht.translate') var deferred = $q.defer(); - $http({ + $http(angular.extend({}, options.$http, { url: options.url, params: { lang: options.key }, method: 'GET' - }).success(function (data) { + })).success(function (data) { deferred.resolve(data); }).error(function (data) { deferred.reject(options.key); diff --git a/src/service/translate.js b/src/service/translate.js index 28f877d3c..084447a19 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -30,7 +30,8 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', $notFoundIndicatorLeft, $notFoundIndicatorRight, $postCompilingEnabled = false, - NESTED_OBJECT_DELIMITER = '.'; + NESTED_OBJECT_DELIMITER = '.', + loaderCache; var version = 'x.y.z'; @@ -705,6 +706,37 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', return $availableLanguageKeys; }; + /** + * @ngdoc function + * @name pascalprecht.translate.$translateProvider#useLoaderCache + * @methodOf pascalprecht.translate.$translateProvider + * + * @description + * Registers a cache for internal $http based loaders. + * {@link pascalprecht.translate.$translateProvider#determinePreferredLanguage determinePreferredLanguage}. + * When false the cache will be disabled (default). When true or undefined + * the cache will be a default (see $cacheFactory). When an object it will + * be treat as a cache object itself: the usage is $http({cache: cache}) + * + * @param {object} cache boolean, string or cache-object + */ + this.useLoaderCache = function (cache) { + if (cache === false) { + // disable cache + loaderCache = undefined; + } else if (cache === true) { + // enable cache using AJS defaults + loaderCache = true; + } else if (typeof(cache) === 'undefined') { + // enable cache using default + loaderCache = '$translationCache'; + } else if (cache) { + // enable cache using given one (see $cacheFactory) + loaderCache = cache; + } + return this; + }; + /** * @ngdoc object * @name pascalprecht.translate.$translate @@ -903,8 +935,17 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', $rootScope.$emit('$translateLoadingStart', {language: key}); pendingLoader = true; + var cache = loaderCache; + if (typeof(cache) === 'string') { + // getting on-demand instance of loader + cache = $injector.get(cache); + } + $injector.get($loaderFactory)(angular.extend($loaderOptions, { - key: key + key: key, + $http: { + cache: cache + } })).then(function (data) { var translationTable = {}; $rootScope.$emit('$translateLoadingSuccess', {language: key}); @@ -1646,6 +1687,20 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', return version; }; + /** + * @ngdoc function + * @name pascalprecht.translate.$translate#loaderCache + * @methodOf pascalprecht.translate.$translate + * + * @description + * Returns the defined loaderCache. + * + * @return {boolean|string|object} current value of loaderCache + */ + $translate.loaderCache = function () { + return loaderCache; + }; + if ($loaderFactory) { // If at least one async loader is defined and there are no @@ -1667,5 +1722,6 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', } return $translate; - }]; + } + ]; }]); diff --git a/src/service/translationCache.js b/src/service/translationCache.js new file mode 100644 index 000000000..6babce309 --- /dev/null +++ b/src/service/translationCache.js @@ -0,0 +1,15 @@ +/** + * @ngdoc service + * @name $translationCache + * @requires $cacheFactory + * + * @description + * The first time a translation table is used, it is loaded in the translation cache for quick retrieval. You + * can load translation tables directly into the cache by consuming the + * `$translationCache` service directly. + * + * @return {object} $cacheFactory object. + */ +angular.module('pascalprecht.translate').factory('$translationCache', ['$cacheFactory', function ($cacheFactory) { + return $cacheFactory('translations'); +}]); \ No newline at end of file diff --git a/test/unit/service/loader-partial.spec.js b/test/unit/service/loader-partial.spec.js index 669ad9f7a..d24b12714 100644 --- a/test/unit/service/loader-partial.spec.js +++ b/test/unit/service/loader-partial.spec.js @@ -598,5 +598,30 @@ describe('pascalprecht.translate', function() { expect(counter).toEqual(2); }); }); + + it('should put a part into a cache and remove from the cache if the part was deleted', function() { + module(function($httpProvider, $translateProvider) { + $httpProvider.defaults.transformRequest.push(CounterHttpInterceptor); + $translateProvider.useLoaderCache(); + }); + + inject(function($translatePartialLoader, $httpBackend, $translationCache) { + $httpBackend.whenGET('/locales/part-en.json').respond(200, '{}'); + + $translatePartialLoader.addPart('part'); + $translatePartialLoader({ + key : 'en', + urlTemplate : '/locales/{part}-{lang}.json', + $http: { + cache: $translationCache + } + }); + $httpBackend.flush(); + expect($translationCache.info().size).toEqual(1); + + $translatePartialLoader.deletePart('part', true); + expect($translationCache.info().size).toEqual(0); + }); + }); }); }); diff --git a/test/unit/service/loader-static-files.spec.js b/test/unit/service/loader-static-files.spec.js index c6cf8e638..c0633780a 100644 --- a/test/unit/service/loader-static-files.spec.js +++ b/test/unit/service/loader-static-files.spec.js @@ -6,10 +6,11 @@ describe('pascalprecht.translate', function () { beforeEach(module('pascalprecht.translate')); - beforeEach(inject(function (_$translate_, _$httpBackend_, _$translateStaticFilesLoader_) { + beforeEach(inject(function (_$translate_, _$httpBackend_, _$translateStaticFilesLoader_, _$translationCache_) { $httpBackend = _$httpBackend_; $translate = _$translate_; $translateStaticFilesLoader = _$translateStaticFilesLoader_; + $translationCache = _$translationCache_; $httpBackend.when('GET', 'lang_de_DE.json').respond({HEADER: 'Ueberschrift'}); $httpBackend.when('GET', 'lang_en_US.json').respond({HEADER:'Header'}); @@ -55,5 +56,19 @@ describe('pascalprecht.translate', function () { expect(typeof promise.then).toBe('function'); $httpBackend.flush(); }); + + it('should put a translation table into a cache', function() { + $httpBackend.expectGET('lang_de_DE.json'); + $translateStaticFilesLoader({ + key: 'de_DE', + prefix: 'lang_', + suffix: '.json', + $http: { + cache: $translationCache + } + }); + $httpBackend.flush(); + expect($translationCache.info().size).toEqual(1); + }); }); }); diff --git a/test/unit/service/loader-url.spec.js b/test/unit/service/loader-url.spec.js index d1f8ebc83..6f20b3e08 100644 --- a/test/unit/service/loader-url.spec.js +++ b/test/unit/service/loader-url.spec.js @@ -6,10 +6,11 @@ describe('pascalprecht.translate', function () { beforeEach(module('pascalprecht.translate')); - beforeEach(inject(function (_$translate_, _$httpBackend_, _$translateUrlLoader_) { + beforeEach(inject(function (_$translate_, _$httpBackend_, _$translateUrlLoader_, _$translationCache_) { $translate = _$translate_; $httpBackend = _$httpBackend_; $translateUrlLoader = _$translateUrlLoader_; + $translationCache = _$translationCache_; $httpBackend.when('GET', 'foo/bar.json?lang=de_DE').respond({ it: 'works' @@ -44,6 +45,19 @@ describe('pascalprecht.translate', function () { $httpBackend.flush(); }); + it('should put a translation table into a cache', function() { + $httpBackend.expectGET('foo/bar.json?lang=de_DE'); + $translateUrlLoader({ + key: 'de_DE', + url: 'foo/bar.json', + $http: { + cache: $translationCache + } + }); + $httpBackend.flush(); + expect($translationCache.info().size).toEqual(1); + }); + it('should return a promise', function () { var promise = $translateUrlLoader({ key: 'de_DE', From d1745e4125c6fdda0f024a64a7c37e84d10f1fbd Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Mon, 8 Sep 2014 14:51:16 +0200 Subject: [PATCH 20/29] fix(service): `$nextLang` should be not unset parallel loadings resolves #647 --- src/service/translate.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index 084447a19..a1738ece9 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -1455,12 +1455,14 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', translations(translation.key, translation.table); deferred.resolve(translation.key); + useLanguage(translation.key); if ($nextLang === key) { - useLanguage(translation.key); $nextLang = undefined; } }, function (key) { - $nextLang = undefined; + if ($nextLang === key) { + $nextLang = undefined; + } $rootScope.$emit('$translateChangeError', {language: key}); deferred.reject(key); $rootScope.$emit('$translateChangeEnd', {language: key}); From 8613befe9766bcf20ea4cdbb59cb9000d87e83a4 Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 17:03:21 +0200 Subject: [PATCH 21/29] feat(loader): apply support for loaderOptions.$http ```js // i.e. $translationProvider.useStaticFilesLoader({$http: {method: 'JSONP'}}); ``` --- src/service/translate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index a1738ece9..23bda39bc 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -943,9 +943,9 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', $injector.get($loaderFactory)(angular.extend($loaderOptions, { key: key, - $http: { + $http: angular.extend({}, $loaderOptions.$http, { cache: cache - } + }) })).then(function (data) { var translationTable = {}; $rootScope.$emit('$translateLoadingSuccess', {language: key}); From 98d429dbebcbee6e945cc4735e46a098aac7f066 Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 17:37:30 +0200 Subject: [PATCH 22/29] fix(service): avoid possible doubled requested on refresh() --- src/service/translate.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index 23bda39bc..904d96374 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -1553,17 +1553,18 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', if (!langKey) { // if there's no language key specified we refresh ALL THE THINGS! - var tables = []; + var tables = [], loadingKeys = {}; // reload registered fallback languages if ($fallbackLanguage && $fallbackLanguage.length) { for (var i = 0, len = $fallbackLanguage.length; i < len; i++) { tables.push(loadAsync($fallbackLanguage[i])); + loadingKeys[$fallbackLanguage[i]] = true; } } // reload currently used language - if ($uses) { + if ($uses && !loadingKeys[$uses]) { tables.push(loadAsync($uses)); } From 9aaa9a0db12141fde6665d6fbbcd0279f6ccedfe Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 19:00:51 +0200 Subject: [PATCH 23/29] fix(service): avoid possible npe in internal getTranslationTable() Relates #723 --- src/service/translate.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index 904d96374..6c4cc87c8 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -1015,12 +1015,13 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', var deferred = $q.defer(); if (Object.prototype.hasOwnProperty.call($translationTable, langKey)) { deferred.resolve($translationTable[langKey]); - return deferred.promise; - } else { + } else if (langPromises[langKey]) { langPromises[langKey].then(function (data) { translations(data.key, data.table); deferred.resolve(data.table); }, deferred.reject); + } else { + deferred.reject(); } return deferred.promise; }; From cf86dfa9f1a541d7c8b96a101f4f5a060ba1af88 Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 19:10:56 +0200 Subject: [PATCH 24/29] Remove unnecessary function scope --- src/service/translate.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index 6c4cc87c8..1660fdf9a 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -1128,9 +1128,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', if (fallbackLanguageIndex < $fallbackLanguage.length) { var langKey = $fallbackLanguage[fallbackLanguageIndex]; getFallbackTranslation(langKey, translationId, interpolateParams, Interpolator).then( - function (translation) { - deferred.resolve(translation); - }, + deferred.resolve, function () { // Look in the next fallback language for a translation. // It delays the resolving by passing another promise to resolve. From dd68c8e0c18975cfac0c691a402c7e11ea29e0c2 Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 19:12:18 +0200 Subject: [PATCH 25/29] Simplify promise handling --- src/service/translate.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index 1660fdf9a..26fcf106f 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -1132,8 +1132,7 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', function () { // Look in the next fallback language for a translation. // It delays the resolving by passing another promise to resolve. - var nextFallbackLanguagePromise = resolveForFallbackLanguage(fallbackLanguageIndex + 1, translationId, interpolateParams, Interpolator); - deferred.resolve(nextFallbackLanguagePromise); + resolveForFallbackLanguage(fallbackLanguageIndex + 1, translationId, interpolateParams, Interpolator).then(deferred.resolve); } ); } else { From bafcc9bc73e080c866be8007f6f3eda4b3477a06 Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 19:13:34 +0200 Subject: [PATCH 26/29] Fix jshint issue --- test/unit/filter/translate.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/filter/translate.spec.js b/test/unit/filter/translate.spec.js index 73d7a8eba..d489cba7c 100644 --- a/test/unit/filter/translate.spec.js +++ b/test/unit/filter/translate.spec.js @@ -93,11 +93,11 @@ describe('pascalprecht.translate', function () { }); } else { it('should replace interpolate directive on element with given values', function () { - $rootScope['__this'] = {value: 'bar'}; + $rootScope.__this = {value: 'bar'}; var element = $compile(angular.element('<div>{{"TRANSLATION_ID" | translate: __this}}</div>'))($rootScope); $rootScope.$digest(); expect(element.html()).toEqual('Lorem Ipsum bar'); - $rootScope['__this'] = undefined; + $rootScope.__this = undefined; }); } }); From 3efaac5b7d0e64fa84bccf658fb452515898ec62 Mon Sep 17 00:00:00 2001 From: tsaikd <tsaikd@gmail.com> Date: Fri, 19 Sep 2014 00:01:20 +0800 Subject: [PATCH 27/29] feat(service): interpolate translationId in case of rejected translation Closes #730 --- src/service/translate.js | 4 ++-- test/unit/service/translate.spec.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/service/translate.js b/src/service/translate.js index 26fcf106f..06a1ca9a2 100644 --- a/src/service/translate.js +++ b/src/service/translate.js @@ -1664,8 +1664,8 @@ angular.module('pascalprecht.translate').provider('$translate', ['$STORAGE_KEY', } if (!result && result !== '') { - // Return translation if not found anything. - result = translationId; + // Return translation of default interpolator if not found anything. + result = defaultInterpolator.interpolate(translationId, interpolateParams); if ($missingTranslationHandlerFactory && !pendingLoader) { result = translateByHandler(translationId); } diff --git a/test/unit/service/translate.spec.js b/test/unit/service/translate.spec.js index 5c27ac3f7..3b0ccce38 100644 --- a/test/unit/service/translate.spec.js +++ b/test/unit/service/translate.spec.js @@ -1639,5 +1639,9 @@ describe('pascalprecht.translate', function () { it('should return translation id if translation id nost exist', function () { expect($translate.instant('FOO3')).toEqual('FOO3'); }); + + it('should return translation id with default interpolator if translation id nost exist', function () { + expect($translate.instant('FOO4 {{value}}', {'value': 'PARAM'})).toEqual('FOO4 PARAM'); + }); }); }); From da745d19bbfa540b055c57e8cdf413334d7334eb Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Wed, 17 Sep 2014 12:42:28 +0200 Subject: [PATCH 28/29] chore(*): introduce additional scopes for testing different AJS versions Example usage: ```TEST_SCOPE=angular_1.3.x grunt test``` runs all tests against latest AJS 1.3 release Run `grunt install-test` to ensure all scopes' dependencies are fully available. More commands: * `npm run-script test-scopes` runs all available scopes (entries in `test_scopes/`) Adding new scopes (or remove it again): * Check entries in .gitignore, .npmignore * Add directory in test_scopes with a bower.json * Add matrix build in .travis.yaml --- .gitignore | 3 +- .npmignore | 1 + .travis.yml | 5 ++++ Gruntfile.js | 31 ++++++++++++++++++++- karma.midway.conf.js | 12 ++++++-- karma.unit.conf.js | 14 +++++++--- karma.util.conf.js | 41 ++++++++++++++++++++++++++++ package.json | 4 ++- test_scopes/angular_1.2.x/.bowerrc | 3 ++ test_scopes/angular_1.2.x/bower.json | 26 ++++++++++++++++++ test_scopes/angular_1.3.x/.bowerrc | 3 ++ test_scopes/angular_1.3.x/bower.json | 26 ++++++++++++++++++ 12 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 karma.util.conf.js create mode 100644 test_scopes/angular_1.2.x/.bowerrc create mode 100644 test_scopes/angular_1.2.x/bower.json create mode 100644 test_scopes/angular_1.3.x/.bowerrc create mode 100644 test_scopes/angular_1.3.x/bower.json diff --git a/.gitignore b/.gitignore index cbaabf3bd..92bbcd0b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ /node_modules/ /components/ /bower_components/ -/test_scopes/angular_1.3/bower_components/ +/test_scopes/angular_1.2.x/bower_components/ +/test_scopes/angular_1.3.x/bower_components/ /dist/ /demo/js/angular-translate-latest.js diff --git a/.npmignore b/.npmignore index 8f92424c3..37ac35a8d 100644 --- a/.npmignore +++ b/.npmignore @@ -4,6 +4,7 @@ /identity/ /src/ /test/ +/test_scopes/ /.bowerrc /.editorconfig /.jshintrc diff --git a/.travis.yml b/.travis.yml index ba3672bb7..40e2a441b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,8 @@ before_install: before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start + +env: + - TEST_SCOPE= + - TEST_SCOPE=angular_1.2.x + - TEST_SCOPE=angular_1.3.x diff --git a/Gruntfile.js b/Gruntfile.js index b61bc3042..cfea6d608 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,7 +1,33 @@ +var fs = require('fs'); + module.exports = function (grunt) { require('load-grunt-tasks')(grunt); + // Returns configuration for bower-install plugin + var loadTestScopeConfigurations = function () { + var scopes = fs.readdirSync('./test_scopes').filter(function (filename) { + return filename[0] !== '.'; + }); + var config = { + options : { + color : false, + interactive : false + } + }; + // Create a sub config for each test scope + for (var idx in scopes) { + var scope = scopes[idx]; + config['test_scopes_' + scope] = { + options : { + cwd : 'test_scopes/' + scope, + production : false + } + }; + } + return config; + }; + grunt.initConfig({ pkg: grunt.file.readJSON('bower.json'), @@ -507,7 +533,9 @@ module.exports = function (grunt) { defaults: { src: ['<%= concat.core.dest %>'] } - } + }, + + 'bower-install-simple': loadTestScopeConfigurations() }); @@ -516,6 +544,7 @@ module.exports = function (grunt) { grunt.registerTask('default', ['jshint:all', 'karma']); grunt.registerTask('test', ['karma:unit', 'karma:midway']); + grunt.registerTask('install-test', ['bower-install-simple']); // Advanced test tasks grunt.registerTask('test-headless', ['karma:headless-unit', 'karma:headless-midway']); diff --git a/karma.midway.conf.js b/karma.midway.conf.js index 2093fccaf..ec0d2f901 100644 --- a/karma.midway.conf.js +++ b/karma.midway.conf.js @@ -1,6 +1,12 @@ // Karma configuration +var shared = require('./karma.util.conf.js'); + module.exports = function (config) { + + var scope = process.env.TEST_SCOPE; + shared.log(scope); + config.set({ basePath: '', @@ -8,10 +14,10 @@ module.exports = function (config) { frameworks: ['jasmine'], files: [ - 'bower_components/angular/angular.js', - 'bower_components/ngMidwayTester/src/ngMidwayTester.js', + shared.injectByScope(scope, 'angular/angular.js'), + shared.injectByScope(scope, 'ngMidwayTester/src/ngMidwayTester.js'), 'src/translate.js', - 'bower_components/angular-translate-interpolation-default/angular-translate-interpolation-default.js', + shared.injectByScope(scope, 'angular-translate-interpolation-default/angular-translate-interpolation-default.js'), 'src/**/*.js', 'test/midway/**/*Spec.js' ], diff --git a/karma.unit.conf.js b/karma.unit.conf.js index 5773724f9..4ca440622 100644 --- a/karma.unit.conf.js +++ b/karma.unit.conf.js @@ -1,6 +1,12 @@ // Karma configuration +var shared = require('./karma.util.conf.js'); + module.exports = function (config) { + + var scope = process.env.TEST_SCOPE; + shared.log(scope); + config.set({ basePath: '', @@ -8,10 +14,10 @@ module.exports = function (config) { frameworks: ['jasmine'], files: [ - 'bower_components/messageformat/messageformat.js', - 'bower_components/angular/angular.js', - 'bower_components/angular-cookies/angular-cookies.js', - 'bower_components/angular-mocks/angular-mocks.js', + shared.injectByScope(scope, 'messageformat/messageformat.js'), + shared.injectByScope(scope, 'angular/angular.js'), + shared.injectByScope(scope, 'angular-cookies/angular-cookies.js'), + shared.injectByScope(scope, 'angular-mocks/angular-mocks.js'), 'src/translate.js', 'src/**/*.js', 'test/unit/**/*.spec.js' diff --git a/karma.util.conf.js b/karma.util.conf.js new file mode 100644 index 000000000..c75362a9f --- /dev/null +++ b/karma.util.conf.js @@ -0,0 +1,41 @@ +'use strict'; + +var fs = require('fs'); + +var AVAILABLE_SCOPES = [], isValidScope, injectByScope, getAffectiveScope, log; + +(function(undefined){ + AVAILABLE_SCOPES = fs.readdirSync('./test_scopes').filter(function (filename) { + return filename[0] !== '.'; + }); + isValidScope = function (scope) { + return AVAILABLE_SCOPES.indexOf(scope) > -1; + }; + getAffectiveScope = function (scope) { + if (isValidScope(scope)) { + return scope; + } else { + return '(default)'; + } + }; + injectByScope = function (scope, path) { + var prefix = ''; + // unless a scope is given, use the default resources + if (scope && isValidScope(scope)) { + prefix = 'test_scopes/' + scope + '/'; + } + return prefix + 'bower_components/' + path; + }, + log = function (scope) { + console.log('Available test scopes: ', AVAILABLE_SCOPES); + console.log('Currently selected scope: ', getAffectiveScope(scope)); + }; +})(); + +module.exports = { + AVAILABLE_SCOPES: AVAILABLE_SCOPES, + isValidScope: isValidScope, + injectByScope: injectByScope, + getAffectiveScope: getAffectiveScope, + log: log +}; diff --git a/package.json b/package.json index 138b2aace..fe5c781ee 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "scripts": { "prepublish": "bower install", "shipit": "bower install && bower update && grunt prepare-release", - "test": "grunt test" + "test": "grunt install-test && grunt test", + "test-scopes": "grunt install-test && for f in test_scopes/*; do TEST_SCOPE=\"`basename $f`\" grunt test; done" }, "author": { "name": "Pascal Precht" @@ -21,6 +22,7 @@ "karma": "~0.10.9", "grunt-karma": "~0.6.x", "grunt": "~0.4.1", + "grunt-bower-install-simple": "^1.0.3", "grunt-contrib-watch": "~0.4.2", "grunt-contrib-concat": "~0.3.x", "grunt-contrib-uglify": "~0.2.x", diff --git a/test_scopes/angular_1.2.x/.bowerrc b/test_scopes/angular_1.2.x/.bowerrc new file mode 100644 index 000000000..69fad3580 --- /dev/null +++ b/test_scopes/angular_1.2.x/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "bower_components" +} diff --git a/test_scopes/angular_1.2.x/bower.json b/test_scopes/angular_1.2.x/bower.json new file mode 100644 index 000000000..267b644d7 --- /dev/null +++ b/test_scopes/angular_1.2.x/bower.json @@ -0,0 +1,26 @@ +{ + "author": "Pascal Precht", + "name": "angular-translate", + "description": "A translation module for AngularJS", + "version": "0.0.0", + "homepage": "http://github.com/angular-translate/angular-translate", + "ignore": [], + "repository": { + "type": "git", + "url": "git://github.com/angular-translate/angular-translate" + }, + "devDependencies": { + "ngMidwayTester": "yearofmoo/ngMidwayTester", + "angular-translate-interpolation-messageformat": "~0.1.2", + "angular": "~1.2.0", + "angular-mocks": "~1.2.0", + "angular-cookies": "~1.2.0" + }, + "resolutions": { + "angular": "~1.2.0" + }, + "licenses": [{ + "type": "MIT", + "url": "http://www.opensource.org/licenses/MIT" + }] +} diff --git a/test_scopes/angular_1.3.x/.bowerrc b/test_scopes/angular_1.3.x/.bowerrc new file mode 100644 index 000000000..69fad3580 --- /dev/null +++ b/test_scopes/angular_1.3.x/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "bower_components" +} diff --git a/test_scopes/angular_1.3.x/bower.json b/test_scopes/angular_1.3.x/bower.json new file mode 100644 index 000000000..6d3bac87f --- /dev/null +++ b/test_scopes/angular_1.3.x/bower.json @@ -0,0 +1,26 @@ +{ + "author": "Pascal Precht", + "name": "angular-translate", + "description": "A translation module for AngularJS", + "version": "0.0.0", + "homepage": "http://github.com/angular-translate/angular-translate", + "ignore": [], + "repository": { + "type": "git", + "url": "git://github.com/angular-translate/angular-translate" + }, + "devDependencies": { + "ngMidwayTester": "yearofmoo/ngMidwayTester", + "angular-translate-interpolation-messageformat": "~0.1.2", + "angular": "~1.3.0", + "angular-mocks": "~1.3.0", + "angular-cookies": "~1.3.0" + }, + "resolutions": { + "angular": "~1.3.0" + }, + "licenses": [{ + "type": "MIT", + "url": "http://www.opensource.org/licenses/MIT" + }] +} From 8fc13fa085c62e803ee0cec69de76b950e5df024 Mon Sep 17 00:00:00 2001 From: knalli <knallisworld@googlemail.com> Date: Thu, 18 Sep 2014 16:44:27 +0200 Subject: [PATCH 29/29] docs(loader): add guide (de, en) --- .../guide/de/12_asynchronous-loading.ngdoc | 46 ++++++++++++++++++ .../guide/en/12_asynchronous-loading.ngdoc | 48 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/docs/content/guide/de/12_asynchronous-loading.ngdoc b/docs/content/guide/de/12_asynchronous-loading.ngdoc index b2cca2f72..26b64e2c6 100644 --- a/docs/content/guide/de/12_asynchronous-loading.ngdoc +++ b/docs/content/guide/de/12_asynchronous-loading.ngdoc @@ -246,6 +246,52 @@ Sprache zur Laufzeit mit `$translate.use()` wechselt. Für den Fall dass die Dat asynchron geladen werden ändert sich nichts. `$translate.use()` überprüft ob die angefragte Sprache vorhanden ist und wenn nicht, wird diese erst geladen. +## Konfiguration eines Loaders + +Jedem Loader kann eine erweiterte Konfiguration `options` angegeben werden. Dies +gilt sowohl für den allgemeinen Konstructor `useLoader(name, options)` als auch +die Shortcut-Konstruktoren wie `useStaticFilesLoader(options)`: + +<pre> +$translationProvider.useLoader('customLoader', { + settingA: 'foobar' +}); +$translationProvider.useStaticFilesLoader({ + $http: { + method: 'POST' + } +}); +</pre> + +Die Eigenschaft `$http` wird entsprechend durchgereicht. Nur das Attribut `cache` wird ggf. überschrieben +(siehe nächstes Kapitel). + +## Benutzung eines Caches + +Bei der Verwendung der Standard Loader kann man das Caching steuern. Weitere Informationen +über Caches finden sich in der +[offiziellen AngularJS Dokumentation](https://docs.angularjs.org/api/ng/type/$cacheFactory.Cache). + +Den Cache kann man sehr leicht mit folgender Konfiguration aktivieren: + +<pre> +$translationProvider.useLoaderCache(true); // default ist false, also deaktiviert +</pre> + +Falls Du bereits eine eigene Instanz konfiguriert hast, kannst Du diese auch direkt übergeben: + +<pre> +$translationProvider.useLoaderCache(yourSpecialCacheService); +</pre> + +Angular-Translate unterstützt auch das Lazy-Binding, so dass auch folgendes funktioniert: + +<pre> +$translationProvider.useLoaderCache('yourSpecialCacheService'); +</pre> + +Die Instanz mit der ID `yourSpecialCacheService` wird erst bei Bedarf aus dem Kontext geladen. + ## FOUC - Flash of untranslated content Es gibt einen Nachteil wenn man Asynchrone Loader verwendet. Für keinen kurzen diff --git a/docs/content/guide/en/12_asynchronous-loading.ngdoc b/docs/content/guide/en/12_asynchronous-loading.ngdoc index 0fe16b433..56f7487e4 100644 --- a/docs/content/guide/en/12_asynchronous-loading.ngdoc +++ b/docs/content/guide/en/12_asynchronous-loading.ngdoc @@ -262,6 +262,54 @@ registered loader to get it down! Lazy loading at it best! **Note**: Please notice that in case of using `partialLoader` you have to refresh translation tables first! +## Configuration of a loader + +Each loader can be applied a dedicated configuration `options`, both for the common constructor +`useLoader()` +Jedem Loader kann eine erweiterte Konfiguration angegeben werden. Dies gilt sowohl für +den allgemeinen Konstructor `useLoader(name, options)` als auch die Shortcut-Konstruktoren +wie `useStaticFilesLoader(options)`: + +<pre> +$translationProvider.useLoader('customLoader', { + settingA: 'foobar' +}); +$translationProvider.useStaticFilesLoader({ + $http: { + method: 'POST' + } +}); +</pre> + +The property `$http` will be used internally in the loaders, except attribute `cache` could be +overridden (see next chapter)). + +## Using a cache + +In order to control the caching behavior of the existing loaders, you can use an +cache instance. See more details about this at the +[Official AngularJS Docs](https://docs.angularjs.org/api/ng/type/$cacheFactory.Cache). + +In order to enable a standard cache, you can use following shortcut: + +<pre> +$translationProvider.useLoaderCache(true); // default is false which means disable +</pre> + +If you have already an instance (i.e. advanced configuration), you can bind this: + +<pre> +$translationProvider.useLoaderCache(yourSpecialCacheService); +</pre> + +Angular-Translate also supports lazy binding for instances, so this will work, too: + +<pre> +$translationProvider.useLoaderCache('yourSpecialCacheService'); +</pre> + +The instance named with ID `yourspecialCacheService` will be looked up on demand. + ## FOUC - Flash of untranslated content There's one drawback when using asynchronous loaders to get your translation data