@@ -904,4 +904,68 @@ describe('pascalprecht.translate', function () {
904
904
expect ( element . html ( ) ) . toBe ( 'My content' ) ;
905
905
} ) ;
906
906
} ) ;
907
+
908
+ describe ( 'handling newlines in interpolation' , function ( ) {
909
+
910
+ var $compile , $rootScope , element ;
911
+
912
+ beforeEach ( module ( 'pascalprecht.translate' , function ( $translateProvider ) {
913
+ $translateProvider
914
+ . translations ( 'en' , {
915
+ 'TRANSLATION_ID' : 'foo' ,
916
+ 'abcfoodef' : 'BOGUS?' ,
917
+ 'foo' : 'FOOGUS?'
918
+ } )
919
+ . preferredLanguage ( 'en' ) ;
920
+ } ) ) ;
921
+
922
+ beforeEach ( inject ( function ( _$compile_ , _$rootScope_ ) {
923
+ $compile = _$compile_ ;
924
+ $rootScope = _$rootScope_ ;
925
+ } ) ) ;
926
+
927
+ it ( 'should handle newlines embedded in interpolation expression' , function ( ) {
928
+ $rootScope . translationId = 'TRANSLATION_ID' ;
929
+ element = $compile ( '<div translate>{{\ntranslationId\n}}</div>' ) ( $rootScope ) ;
930
+ $rootScope . $digest ( ) ;
931
+ expect ( element . text ( ) ) . toBe ( 'foo' ) ;
932
+ } ) ;
933
+
934
+ it ( 'should handle newlines embedded in interpolation expression for translate element' , function ( ) {
935
+ $rootScope . translationId = 'TRANSLATION_ID' ;
936
+ element = $compile ( '<translate>{{\ntranslationId\n}}</translate>' ) ( $rootScope ) ;
937
+ $rootScope . $digest ( ) ;
938
+ expect ( element . text ( ) ) . toBe ( 'foo' ) ;
939
+ } ) ;
940
+
941
+ it ( 'should handle newlines embedded in interpolation expression with surrounding text' , function ( ) {
942
+ $rootScope . translationId = 'TRANSLATION_ID' ;
943
+ element = $compile ( '<div translate>abc{{\ntranslationId\n}}def</div>' ) ( $rootScope ) ;
944
+ $rootScope . $digest ( ) ;
945
+ expect ( element . text ( ) ) . toBe ( 'abcfoodef' ) ;
946
+ } ) ;
947
+
948
+ it ( 'should handle newlines embedded in and surrounding interpolation expression' , function ( ) {
949
+ $rootScope . translationId = 'TRANSLATION_ID' ;
950
+ element = $compile ( '<div translate>abc\n{{\ntranslationId\n}}\ndef</div>' ) ( $rootScope ) ;
951
+ $rootScope . $digest ( ) ;
952
+ expect ( element . text ( ) ) . toBe ( 'abc foo def' ) ;
953
+ } ) ;
954
+
955
+ it ( 'should handle newlines embedded in complex interpolation expression' , function ( ) {
956
+ $rootScope . translationId = 'TRANSLATION_ID' ;
957
+ $rootScope . var1 = 'TRANSLATION' ;
958
+ $rootScope . var2 = 'ID' ;
959
+ element = $compile ( '<div translate>\nabc{{\n var1 + \n "_" + var2\n }}def\n </div>' ) ( $rootScope ) ;
960
+ $rootScope . $digest ( ) ;
961
+ expect ( element . text ( ) ) . toBe ( 'abcfoodef' ) ;
962
+ } ) ;
963
+
964
+ it ( 'should handle newlines embedded in interpolation expression in attribute' , function ( ) {
965
+ $rootScope . translationId = 'TRANSLATION_ID' ;
966
+ element = $compile ( '<div translate="{{\ntranslationId\n}}">...</div>' ) ( $rootScope ) ;
967
+ $rootScope . $digest ( ) ;
968
+ expect ( element . text ( ) ) . toBe ( 'foo' ) ;
969
+ } ) ;
970
+ } ) ;
907
971
} ) ;
0 commit comments