@@ -27,6 +27,11 @@ angular.module('localization', []).
27
27
$rootScope . $broadcast ( 'localizeResourcesUpdates' ) ;
28
28
} ,
29
29
30
+ setLanguage : function ( value ) {
31
+ localize . language = value ;
32
+ localize . initLocalizedResources ( ) ;
33
+ } ,
34
+
30
35
initLocalizedResources :function ( ) {
31
36
// build the url to retrieve the localized resource file
32
37
var url = '/i18n/resources-locale_' + localize . language + '.js' ;
@@ -69,47 +74,37 @@ angular.module('localization', []).
69
74
return localize . getLocalizedString ( input ) ;
70
75
} ;
71
76
} ] ) . directive ( 'i18n' , [ 'localize' , function ( localize ) {
72
- return {
73
- restrict : "EAC" ,
74
- link : function ( scope , elm , attrs ) {
75
- scope . $on ( 'localizeResourcesUpdates' , function ( ) {
76
- var token = attrs . i18n ;
77
- var values = token . split ( '|' ) ;
78
- if ( values . length >= 1 ) {
79
- // construct the tag to insert into the element
80
- var tag = localize . getLocalizedString ( values [ 0 ] ) ;
81
- // update the element only if data was returned
82
- if ( ( tag !== null ) && ( tag !== undefined ) && ( tag !== '' ) ) {
83
- if ( values . length > 1 ) {
84
- for ( var index = 1 ; index < values . length ; index ++ ) {
85
- var target = '{' + ( index - 1 ) + '}' ;
86
- tag = tag . replace ( target , values [ index ] ) ;
87
- }
77
+ var i18nDirective = {
78
+ restrict :"EAC" ,
79
+ updateText :function ( elm , token ) {
80
+ var values = token . split ( '|' ) ;
81
+ if ( values . length >= 1 ) {
82
+ // construct the tag to insert into the element
83
+ var tag = localize . getLocalizedString ( values [ 0 ] ) ;
84
+ // update the element only if data was returned
85
+ if ( ( tag !== null ) && ( tag !== undefined ) && ( tag !== '' ) ) {
86
+ if ( values . length > 1 ) {
87
+ for ( var index = 1 ; index < values . length ; index ++ ) {
88
+ var target = '{' + ( index - 1 ) + '}' ;
89
+ tag = tag . replace ( target , values [ index ] ) ;
88
90
}
89
- // insert the text into the element
90
- elm . text ( tag ) ;
91
- } ;
92
- }
91
+ }
92
+ // insert the text into the element
93
+ elm . text ( tag ) ;
94
+ } ;
95
+ }
96
+ } ,
97
+
98
+ link :function ( scope , elm , attrs ) {
99
+ scope . $on ( 'localizeResourcesUpdates' , function ( ) {
100
+ i18nDirective . updateText ( elm , attrs . i18n ) ;
93
101
} ) ;
94
102
95
103
attrs . $observe ( 'i18n' , function ( value ) {
96
- var values = value . split ( '|' ) ;
97
- if ( values . length >= 1 ) {
98
- // construct the tag to insert into the element
99
- var tag = localize . getLocalizedString ( values [ 0 ] ) ;
100
- // update the element only if data was returned
101
- if ( ( tag !== null ) && ( tag !== undefined ) && ( tag !== '' ) ) {
102
- if ( values . length > 1 ) {
103
- for ( var index = 1 ; index < values . length ; index ++ ) {
104
- var target = '{' + ( index - 1 ) + '}' ;
105
- tag = tag . replace ( target , values [ index ] ) ;
106
- }
107
- }
108
- // insert the text into the element
109
- elm . text ( tag ) ;
110
- } ;
111
- }
104
+ i18nDirective . updateText ( elm , attrs . i18n ) ;
112
105
} ) ;
113
106
}
114
107
} ;
108
+
109
+ return i18nDirective ;
115
110
} ] ) ;
0 commit comments