Merge "Fix the docker push"
[clamp.git] / src / main / resources / META-INF / resources / designer / lib / translate-substitution.js
1 //== Translate Substitute Module =============================================//
2
3 /**
4  * For those not using Angular-Translate (pascalprecht.translate), this will sub
5  * in for it so we don't have to include Angular-Translate if we don't want to.
6  */
7
8 var translateSubMod = angular.module('translate.sub',[]);
9
10         /**
11          * $translate Service
12          * Sets up a $translateProvider service to use in your module's config
13          * function.  $translate.Provider syntax is the same as Angular-Translate,
14          * use $translate.Provider.translations(lang,obj) to change the defaults
15          * for modal button, header and message text.
16          */
17         translateSubMod.provider('$translate',[function(){
18                 var _translations = []; // object of key/value translation pairs
19                 var _current = 'en-US'; // default language
20
21                 /**
22                  * Translations
23                  * Set the internal object of translation key/value pairs.
24                  */
25                 this.translations = function(lang,obj){
26                         if(angular.isDefined(lang) && angular.isDefined(obj)){
27                                 _translations[lang] = angular.copy(obj);
28                                 _current = lang;
29                         }
30                 }; // end translations
31
32                 this.$get = [function(){
33                         return {
34                                 /**
35                                  * Instant
36                                  * Retrieve the translation for the given key, if key not found
37                                  * return an empty string.
38                                  * Example: $translate.instant('DIALOGS_OK');
39                                  */
40                                 instant : function(what){
41                                         if(angular.isDefined(what) && angular.isDefined(_translations[_current][what]))
42                                                 return _translations[_current][what];
43                                         else
44                                                 return '';
45                                 } // end instant
46                         }; // end return 
47                 }]; // end $get
48
49         }]); // end $translate
50
51         /**
52          * Translate Filter
53          * For use in an Angular template.  
54          * Example: {{"DIALOGS_CLOSE" | translate}}
55          */
56         translateSubMod.filter('translate',['$translate',function($translate){
57                 return function(what){
58                         return $translate.instant(what);
59                 };
60         }]); // end translate / translate.sub