@@ -132,7 +132,7 @@ describe("Catalog", function () {
132
132
} )
133
133
134
134
describe ( "POT Flow" , function ( ) {
135
- it ( ' Should merge source messages from template if provided' , ( ) => {
135
+ it ( " Should merge source messages from template if provided" , ( ) => {
136
136
const catalog = new Catalog (
137
137
{
138
138
name : "messages" ,
@@ -144,21 +144,21 @@ describe("Catalog", function () {
144
144
exclude : [ ] ,
145
145
} ,
146
146
mockConfig ( {
147
- locales : [ 'en' , 'pl' ] ,
147
+ locales : [ "en" , "pl" ] ,
148
148
} )
149
149
)
150
150
151
- const translations = catalog . getTranslations ( 'pl' , {
152
- sourceLocale : 'en' ,
151
+ const translations = catalog . getTranslations ( "pl" , {
152
+ sourceLocale : "en" ,
153
153
fallbackLocales : {
154
- default : 'en'
155
- }
156
- } ) ;
154
+ default : "en" ,
155
+ } ,
156
+ } )
157
157
158
158
expect ( translations ) . toMatchSnapshot ( )
159
159
} )
160
160
161
- it ( ' Should get translations from template if locale file not presented' , ( ) => {
161
+ it ( " Should get translations from template if locale file not presented" , ( ) => {
162
162
const catalog = new Catalog (
163
163
{
164
164
name : "messages" ,
@@ -170,18 +170,18 @@ describe("Catalog", function () {
170
170
exclude : [ ] ,
171
171
} ,
172
172
mockConfig ( {
173
- locales : [ 'en' , 'pl' ] ,
173
+ locales : [ "en" , "pl" ] ,
174
174
} )
175
175
)
176
176
177
- const translations = catalog . getTranslations ( 'en' , {
178
- sourceLocale : 'en' ,
177
+ const translations = catalog . getTranslations ( "en" , {
178
+ sourceLocale : "en" ,
179
179
fallbackLocales : {
180
- default : 'en'
181
- }
182
- } ) ;
180
+ default : "en" ,
181
+ } ,
182
+ } )
183
183
184
- console . log ( translations ) ;
184
+ console . log ( translations )
185
185
expect ( translations ) . toMatchSnapshot ( )
186
186
} )
187
187
} )
@@ -207,15 +207,18 @@ describe("Catalog", function () {
207
207
{
208
208
name : "messages" ,
209
209
path : "locales/{locale}" ,
210
- include : [ fixture ( "collect/componentA" ) , fixture ( "collect/componentB.js" ) ] ,
210
+ include : [
211
+ fixture ( "collect/componentA" ) ,
212
+ fixture ( "collect/componentB.js" ) ,
213
+ ] ,
211
214
exclude : [ ] ,
212
215
} ,
213
216
mockConfig ( )
214
217
)
215
218
216
219
const messages = await catalog . collect ( {
217
220
...defaultMakeOptions ,
218
- files : [ fixture ( "collect/componentA" ) ]
221
+ files : [ fixture ( "collect/componentA" ) ] ,
219
222
} )
220
223
expect ( messages ) . toMatchSnapshot ( )
221
224
} )
@@ -718,6 +721,34 @@ describe("getCatalogs", function () {
718
721
] )
719
722
} )
720
723
724
+ it ( "should expand {name} multiple times in path" , function ( ) {
725
+ mockFs ( {
726
+ componentA : {
727
+ "index.js" : mockFs . file ( ) ,
728
+ } ,
729
+ } )
730
+
731
+ const config = mockConfig ( {
732
+ catalogs : [
733
+ {
734
+ path : "{name}/locales/{locale}/{name}_messages_{locale}" ,
735
+ include : [ "./{name}/" ] ,
736
+ } ,
737
+ ] ,
738
+ } )
739
+ expect ( getCatalogs ( config ) ) . toEqual ( [
740
+ new Catalog (
741
+ {
742
+ name : "componentA" ,
743
+ path : "componentA/locales/{locale}/componentA_messages_{locale}" ,
744
+ include : [ "componentA/" ] ,
745
+ exclude : [ ] ,
746
+ } ,
747
+ config
748
+ ) ,
749
+ ] )
750
+ } )
751
+
721
752
it ( "shouldn't expand {name} for ignored directories" , function ( ) {
722
753
mockFs ( {
723
754
componentA : {
@@ -813,6 +844,23 @@ describe("getCatalogForFile", function () {
813
844
expect ( getCatalogForFile ( "./xyz/en.po" , catalogs ) ) . toBeNull ( )
814
845
} )
815
846
847
+ it ( "should return matching catalog and locale if {locale} is present multiple times in path" , function ( ) {
848
+ const catalog = new Catalog (
849
+ {
850
+ name : null ,
851
+ path : "./src/locales/{locale}/messages_{locale}" ,
852
+ include : [ "./src/" ] ,
853
+ } ,
854
+ mockConfig ( { format : "po" } )
855
+ )
856
+ const catalogs = [ catalog ]
857
+
858
+ expect ( getCatalogForFile ( "./src/locales/en/messages_en.po" , catalogs ) ) . toEqual ( {
859
+ locale : "en" ,
860
+ catalog,
861
+ } )
862
+ } )
863
+
816
864
it ( "should return matching catalog and locale" , function ( ) {
817
865
const catalog = new Catalog (
818
866
{
@@ -934,12 +982,12 @@ describe("normalizeRelativePath", function () {
934
982
)
935
983
} )
936
984
937
- it ( "directories without ending slash are correctly treaten as dirs" , function ( ) {
985
+ it ( "directories without ending slash are correctly treaten as dirs" , function ( ) {
938
986
mockFs ( {
939
987
componentA : {
940
988
"index.js" : mockFs . file ( ) ,
941
989
} ,
942
- " componentB" : mockFs . file ( ) ,
990
+ componentB : mockFs . file ( ) ,
943
991
} )
944
992
// checked correctly that is a dir, cuz added that ending slash
945
993
expect ( normalizeRelativePath ( "./componentA" ) ) . toEqual ( "componentA/" )
@@ -1029,23 +1077,26 @@ describe("writeCompiled", function () {
1029
1077
name : "messages" ,
1030
1078
path : path . join ( localeDir , "{locale}" , "messages" ) ,
1031
1079
include : [ ] ,
1032
- exclude : [ ]
1080
+ exclude : [ ] ,
1033
1081
} ,
1034
1082
mockConfig ( )
1035
1083
)
1036
1084
1037
1085
it . each ( [
1038
- { namespace : "es" , extension : / \. m j s $ / } ,
1039
- { namespace : "ts" , extension : / \. t s $ / } ,
1040
- { namespace : undefined , extension : / \. j s $ / } ,
1041
- { namespace : 'cjs' , extension : / \. j s $ / } ,
1042
- { namespace : 'window.test' , extension : / \. j s $ / } ,
1043
- { namespace : 'global.test' , extension : / \. j s $ / }
1044
- ] ) ( 'Should save namespace $namespace in $extension extension' , ( { namespace, extension} ) => {
1045
- const compiledCatalog = createCompiledCatalog ( "en" , { } , { namespace} )
1046
- // Test that the file extension of the compiled catalog is `.mjs`
1047
- expect ( catalog . writeCompiled ( "en" , compiledCatalog , namespace ) ) . toMatch (
1048
- extension
1049
- )
1050
- } )
1086
+ { namespace : "es" , extension : / \. m j s $ / } ,
1087
+ { namespace : "ts" , extension : / \. t s $ / } ,
1088
+ { namespace : undefined , extension : / \. j s $ / } ,
1089
+ { namespace : "cjs" , extension : / \. j s $ / } ,
1090
+ { namespace : "window.test" , extension : / \. j s $ / } ,
1091
+ { namespace : "global.test" , extension : / \. j s $ / } ,
1092
+ ] ) (
1093
+ "Should save namespace $namespace in $extension extension" ,
1094
+ ( { namespace, extension } ) => {
1095
+ const compiledCatalog = createCompiledCatalog ( "en" , { } , { namespace } )
1096
+ // Test that the file extension of the compiled catalog is `.mjs`
1097
+ expect ( catalog . writeCompiled ( "en" , compiledCatalog , namespace ) ) . toMatch (
1098
+ extension
1099
+ )
1100
+ }
1101
+ )
1051
1102
} )
0 commit comments