@@ -132,7 +132,7 @@ describe("Catalog", function () {
132132 } )
133133
134134 describe ( "POT Flow" , function ( ) {
135- it ( ' Should merge source messages from template if provided' , ( ) => {
135+ it ( " Should merge source messages from template if provided" , ( ) => {
136136 const catalog = new Catalog (
137137 {
138138 name : "messages" ,
@@ -144,21 +144,21 @@ describe("Catalog", function () {
144144 exclude : [ ] ,
145145 } ,
146146 mockConfig ( {
147- locales : [ 'en' , 'pl' ] ,
147+ locales : [ "en" , "pl" ] ,
148148 } )
149149 )
150150
151- const translations = catalog . getTranslations ( 'pl' , {
152- sourceLocale : 'en' ,
151+ const translations = catalog . getTranslations ( "pl" , {
152+ sourceLocale : "en" ,
153153 fallbackLocales : {
154- default : 'en'
155- }
156- } ) ;
154+ default : "en" ,
155+ } ,
156+ } )
157157
158158 expect ( translations ) . toMatchSnapshot ( )
159159 } )
160160
161- it ( ' Should get translations from template if locale file not presented' , ( ) => {
161+ it ( " Should get translations from template if locale file not presented" , ( ) => {
162162 const catalog = new Catalog (
163163 {
164164 name : "messages" ,
@@ -170,18 +170,18 @@ describe("Catalog", function () {
170170 exclude : [ ] ,
171171 } ,
172172 mockConfig ( {
173- locales : [ 'en' , 'pl' ] ,
173+ locales : [ "en" , "pl" ] ,
174174 } )
175175 )
176176
177- const translations = catalog . getTranslations ( 'en' , {
178- sourceLocale : 'en' ,
177+ const translations = catalog . getTranslations ( "en" , {
178+ sourceLocale : "en" ,
179179 fallbackLocales : {
180- default : 'en'
181- }
182- } ) ;
180+ default : "en" ,
181+ } ,
182+ } )
183183
184- console . log ( translations ) ;
184+ console . log ( translations )
185185 expect ( translations ) . toMatchSnapshot ( )
186186 } )
187187 } )
@@ -207,15 +207,18 @@ describe("Catalog", function () {
207207 {
208208 name : "messages" ,
209209 path : "locales/{locale}" ,
210- include : [ fixture ( "collect/componentA" ) , fixture ( "collect/componentB.js" ) ] ,
210+ include : [
211+ fixture ( "collect/componentA" ) ,
212+ fixture ( "collect/componentB.js" ) ,
213+ ] ,
211214 exclude : [ ] ,
212215 } ,
213216 mockConfig ( )
214217 )
215218
216219 const messages = await catalog . collect ( {
217220 ...defaultMakeOptions ,
218- files : [ fixture ( "collect/componentA" ) ]
221+ files : [ fixture ( "collect/componentA" ) ] ,
219222 } )
220223 expect ( messages ) . toMatchSnapshot ( )
221224 } )
@@ -718,6 +721,34 @@ describe("getCatalogs", function () {
718721 ] )
719722 } )
720723
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+
721752 it ( "shouldn't expand {name} for ignored directories" , function ( ) {
722753 mockFs ( {
723754 componentA : {
@@ -813,6 +844,23 @@ describe("getCatalogForFile", function () {
813844 expect ( getCatalogForFile ( "./xyz/en.po" , catalogs ) ) . toBeNull ( )
814845 } )
815846
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+
816864 it ( "should return matching catalog and locale" , function ( ) {
817865 const catalog = new Catalog (
818866 {
@@ -934,12 +982,12 @@ describe("normalizeRelativePath", function () {
934982 )
935983 } )
936984
937- it ( "directories without ending slash are correctly treaten as dirs" , function ( ) {
985+ it ( "directories without ending slash are correctly treaten as dirs" , function ( ) {
938986 mockFs ( {
939987 componentA : {
940988 "index.js" : mockFs . file ( ) ,
941989 } ,
942- " componentB" : mockFs . file ( ) ,
990+ componentB : mockFs . file ( ) ,
943991 } )
944992 // checked correctly that is a dir, cuz added that ending slash
945993 expect ( normalizeRelativePath ( "./componentA" ) ) . toEqual ( "componentA/" )
@@ -1029,23 +1077,26 @@ describe("writeCompiled", function () {
10291077 name : "messages" ,
10301078 path : path . join ( localeDir , "{locale}" , "messages" ) ,
10311079 include : [ ] ,
1032- exclude : [ ]
1080+ exclude : [ ] ,
10331081 } ,
10341082 mockConfig ( )
10351083 )
10361084
10371085 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+ )
10511102} )
0 commit comments