Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

"custom error Handler" invoked three times for each translate directive #1616

Open
fmunafo opened this issue Oct 17, 2016 · 4 comments
Open

Comments

@fmunafo
Copy link

fmunafo commented Oct 17, 2016

Why custom handler function is invoked three times using translateas attribute and six times using translateas element (three for the element and three for the attribute)?

(I've also noticed that with translate 2.10.0 it happens 4 and 8 times)

Thanks,
Filippo

<!doctype html>
<html ng-app="myApp">
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.5/angular.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-translate/2.12.1/angular-translate.js"></script>
  </head>
  <body>

    <div>
      <p translate="test_id_1"></p>
      <translate translate="test_id_2"></translate>
    </div>

    <script>
      var translations = {};

      var app = angular.module('myApp', ['pascalprecht.translate']);

      app.config(['$translateProvider', function ($translateProvider) {
        // add translation table
        $translateProvider
          .translations('en', translations)
          .useMissingTranslationHandler('myCustomHandlerFactory')
      }]);

      app.factory('myCustomHandlerFactory', function () {
        return function (translationID, uses) {
          if (translationID == "test_id_1") {
            console.log("handler per " + translationID);
            return 'NO VALUE FOR test_id_1';
          } else {
            console.log("handler per " + translationID);
            return 'NO VALUE FOR test_id_2';
          }
        };
      });  
    </script>
  </body>
</html>
@knalli
Copy link
Member

knalli commented Oct 17, 2016

Hello,

as we had already mentioned in the issue's template, we need a working and as minimal as possible demo covering your specific use case or issue.

Follow these steps:

  1. Please open this plnkr base.
  2. Fork it (at the top left).
  3. Ensure the version of AngularJS and angular-translate is correct.
  4. Ensure all angular-translate plugins are available; reduce and remove anything you can.
  5. Write a minimal as possible demo for your specific issue.
  6. Save and freeze. Provide us the final link to your demo.

@tspaeth
Copy link
Member

tspaeth commented Oct 17, 2016

This looks already strange...

 <translate translate="test_id_2"></translate>

@fmunafo
Copy link
Author

fmunafo commented Oct 17, 2016

@fmunafo fmunafo changed the title "custom error Handler" invoked three or six times "custom error Handler" invoked three times for each translate directive Oct 19, 2016
@knalli
Copy link
Member

knalli commented Feb 12, 2017

Translation will be tried for

  • observeElementTranslation(iAttr.translate);
  • updateTranslations(); (last one)
  • updateTranslations(); (in observe of translate)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants