Plato on Github
Report Home
directive/translate-language.js
Maintainability
85.55
Lines of code
70
Difficulty
5.25
Estimated Errors
0.10
Function weight
By Complexity
By SLOC
angular.module('pascalprecht.translate') /** * @ngdoc directive * @name pascalprecht.translate.directive:translateLanguage * @restrict A * * @description * Forces the language to the directives in the underlying scope. * * @param {string=} translate language that will be negotiated. * * @example <example module="ngView"> <file name="index.html"> <div> <div> <h1 translate>HELLO</h1> </div> <div translate-language="de"> <h1 translate>HELLO</h1> </div> </div> </file> <file name="script.js"> angular.module('ngView', ['pascalprecht.translate']) .config(function ($translateProvider) { $translateProvider .translations('en',{ 'HELLO': 'Hello world!' }) .translations('de',{ 'HELLO': 'Hallo Welt!' }) .preferredLanguage('en'); }); </file> </example> */ .directive('translateLanguage', translateLanguageDirective); function translateLanguageDirective() { 'use strict'; return { restrict: 'A', scope: true, compile: function () { return function linkFn(scope, iElement, iAttrs) { iAttrs.$observe('translateLanguage', function (newTranslateLanguage) { scope.translateLanguage = newTranslateLanguage; }); scope.$watch('translateLanguage', function(){ scope.$broadcast('translateLanguageChanged'); }); }; } }; } translateLanguageDirective.displayName = 'translateLanguageDirective';