@@ -10,14 +10,12 @@ import { isString, warn } from '@intlify/shared'
10
10
import {
11
11
createComposer ,
12
12
MissingHandler ,
13
- addPreCompileMessages ,
14
13
ComposerOptions ,
15
14
VueMessageType ,
16
15
TransrateVNodeSymbol ,
17
16
NumberPartsSymbol ,
18
17
DatetimePartsSymbol
19
18
} from '../src/composer'
20
- import { generateFormatCacheKey } from '@intlify/shared'
21
19
import { watch , watchEffect , nextTick , Text , createVNode } from 'vue'
22
20
import {
23
21
Locale ,
@@ -960,122 +958,97 @@ describe('getNumberFormat / setNumberFormat / mergeNumberFormat', () => {
960
958
} )
961
959
962
960
describe ( '__i18n' , ( ) => {
963
- test ( 'default value' , ( ) => {
964
- const options = {
965
- __i18n : [
966
- JSON . stringify ( { en : { hello : 'Hello,world!' } } ) ,
967
- JSON . stringify ( {
968
- ja : {
969
- hello : 'こんにちは、世界!' ,
970
- nest : {
971
- foo : {
972
- bar : 'ばー'
973
- }
961
+ test ( 'locale included locale messages' , ( ) => {
962
+ const enResource = {
963
+ locale : '' ,
964
+ resource : {
965
+ en : { hello : ( ) => 'Hello,world!' }
966
+ }
967
+ }
968
+ const jaResource = {
969
+ locale : '' ,
970
+ resource : {
971
+ ja : {
972
+ hello : ( ) => 'こんにちは、世界!' ,
973
+ nest : {
974
+ foo : {
975
+ bar : ( ) => 'ばー'
974
976
}
975
977
}
976
- } )
977
- ]
978
+ }
979
+ }
980
+ }
981
+ const options = {
982
+ __i18n : [ enResource , jaResource ]
978
983
}
979
984
const { messages } = createComposer (
980
985
options as ComposerOptions < VueMessageType >
981
986
)
982
987
expect ( messages . value ) . toEqual ( {
983
- en : { hello : 'Hello,world!' } ,
984
- ja : {
985
- hello : 'こんにちは、世界!' ,
986
- nest : {
987
- foo : {
988
- bar : 'ばー'
989
- }
990
- }
991
- }
988
+ en : enResource . resource . en ,
989
+ ja : jaResource . resource . ja
992
990
} )
993
991
} )
994
992
995
- test ( 'locale messages object' , ( ) => {
996
- const options = {
997
- __i18n : [
998
- { en : { hello : 'Hello,world!' } } ,
999
- {
1000
- ja : {
1001
- hello : 'こんにちは、世界!' ,
1002
- nest : {
1003
- foo : {
1004
- bar : 'ばー'
1005
- }
1006
- }
1007
- }
1008
- }
1009
- ]
993
+ test ( 'locale not included locale messages' , ( ) => {
994
+ const enResource = {
995
+ locale : 'en' ,
996
+ resource : { hello : ( ) => 'Hello,world!' }
1010
997
}
1011
- const { messages } = createComposer (
1012
- options as ComposerOptions < VueMessageType >
1013
- )
1014
- expect ( messages . value ) . toEqual ( {
1015
- en : { hello : 'Hello,world!' } ,
1016
- ja : {
1017
- hello : 'こんにちは、世界!' ,
998
+ const jaResource = {
999
+ locale : 'ja' ,
1000
+ resource : {
1001
+ hello : ( ) => 'こんにちは、世界!' ,
1018
1002
nest : {
1019
1003
foo : {
1020
- bar : 'ばー'
1004
+ bar : ( ) => 'ばー'
1021
1005
}
1022
1006
}
1023
1007
}
1024
- } )
1025
- } )
1026
-
1027
- test ( 'merge locale messages' , ( ) => {
1028
- const msgFn = ( ) => 'ふー'
1008
+ }
1029
1009
const options = {
1030
- __i18n : [
1031
- JSON . stringify ( { en : { hello : 'Hello,world!' } } ) ,
1032
- JSON . stringify ( { ja : { hello : 'こんにちは、世界!' } } )
1033
- ] ,
1034
- messages : {
1035
- en : { foo : 'foo' } ,
1036
- ja : { foo : msgFn }
1037
- }
1010
+ __i18n : [ enResource , jaResource ]
1038
1011
}
1039
1012
const { messages } = createComposer (
1040
1013
options as ComposerOptions < VueMessageType >
1041
1014
)
1042
- expect ( messages . value ! . en ) . toEqual ( {
1043
- hello : 'Hello,world!' ,
1044
- foo : 'foo'
1045
- } )
1046
- expect ( messages . value ! . ja ) . toEqual ( {
1047
- hello : 'こんにちは、世界!' ,
1048
- foo : msgFn
1015
+ expect ( messages . value ) . toEqual ( {
1016
+ en : enResource . resource ,
1017
+ ja : jaResource . resource
1049
1018
} )
1050
1019
} )
1051
1020
1052
- test ( 'function + locale messages' , ( ) => {
1053
- const functions = Object . create ( null )
1054
- const msg1 = ( ) => { }
1055
- const msg2 = ( ) => { }
1056
- functions [ generateFormatCacheKey ( 'en' , 'hello' , 'hello,world' ) ] = msg1
1057
- functions [
1058
- generateFormatCacheKey ( 'ja' , 'hello.hello' , 'こんにちは、世界' )
1059
- ] = msg2
1021
+ test ( 'merge locale messages' , ( ) => {
1022
+ const msgFnEn = ( ) => 'foo'
1023
+ const msgFnJa = ( ) => 'ふー'
1024
+ const enI18nFn = ( ) => 'Hello,world!'
1025
+ const jaI18nFn = ( ) => 'こんにちは、世界!'
1060
1026
const options = {
1061
- __i18n : ( ) => ( { functions } ) ,
1027
+ __i18n : [
1028
+ {
1029
+ locale : 'en' ,
1030
+ resource : { hello : enI18nFn }
1031
+ } ,
1032
+ {
1033
+ locale : 'ja' ,
1034
+ resource : { hello : jaI18nFn }
1035
+ }
1036
+ ] ,
1062
1037
messages : {
1063
- en : { foo : 'foo' } ,
1064
- ja : { foo : 'ふー' }
1038
+ en : { foo : msgFnEn } ,
1039
+ ja : { foo : msgFnJa }
1065
1040
}
1066
1041
}
1067
1042
const { messages } = createComposer (
1068
1043
options as ComposerOptions < VueMessageType >
1069
1044
)
1070
1045
expect ( messages . value ! . en ) . toEqual ( {
1071
- hello : msg1 ,
1072
- foo : 'foo'
1046
+ hello : enI18nFn ,
1047
+ foo : msgFnEn
1073
1048
} )
1074
1049
expect ( messages . value ! . ja ) . toEqual ( {
1075
- hello : {
1076
- hello : msg2
1077
- } ,
1078
- foo : 'ふー'
1050
+ hello : jaI18nFn ,
1051
+ foo : msgFnJa
1079
1052
} )
1080
1053
} )
1081
1054
} )
@@ -1208,28 +1181,6 @@ describe('__datetimeParts', () => {
1208
1181
} )
1209
1182
} )
1210
1183
1211
- test ( 'addPreCompileMessages' , ( ) => {
1212
- const messages : any = { }
1213
- const functions = Object . create ( null )
1214
- const msg1 = ( ) => { }
1215
- const msg2 = ( ) => { }
1216
- functions [ generateFormatCacheKey ( 'en' , 'hello' , 'hello,world' ) ] = msg1
1217
- functions [
1218
- generateFormatCacheKey ( 'ja' , 'foo.bar.hello' , 'こんにちは、世界' )
1219
- ] = msg2
1220
- addPreCompileMessages ( messages , functions )
1221
- expect ( messages ! [ 'en' ] ) . toMatchObject ( {
1222
- hello : msg1
1223
- } )
1224
- expect ( messages ! [ 'ja' ] ) . toMatchObject ( {
1225
- foo : {
1226
- bar : {
1227
- hello : msg2
1228
- }
1229
- }
1230
- } )
1231
- } )
1232
-
1233
1184
describe ( 'root' , ( ) => {
1234
1185
test ( 'global' , ( ) => {
1235
1186
const __root = createComposer ( {
0 commit comments