@@ -67,37 +67,36 @@ public function dump(MessageCatalogue $messages, $options = [])
6767 throw new InvalidArgumentException ('The file dumper needs a path option. ' );
6868 }
6969
70- $ hasMessageFormatter = class_exists (\MessageFormatter::class);
71-
7270 // save a file for each domain
7371 foreach ($ messages ->getDomains () as $ domain ) {
74- if ($ hasMessageFormatter ) {
75- $ defaultDomain = $ domain .MessageCatalogue::INTL_DOMAIN_SUFFIX ;
76- $ altDomain = $ domain ;
77- } else {
78- $ defaultDomain = $ domain ;
79- $ altDomain = $ domain .MessageCatalogue::INTL_DOMAIN_SUFFIX ;
80- }
81- $ defaultPath = $ options ['path ' ].'/ ' .$ this ->getRelativePath ($ defaultDomain , $ messages ->getLocale ());
82- $ altPath = $ options ['path ' ].'/ ' .$ this ->getRelativePath ($ altDomain , $ messages ->getLocale ());
83-
84- if (!file_exists ($ defaultPath ) && file_exists ($ altPath )) {
85- [$ defaultPath , $ altPath ] = [$ altPath , $ defaultPath ];
86- }
87-
88- if (!file_exists ($ defaultPath )) {
89- $ directory = \dirname ($ defaultPath );
72+ $ fullpath = $ options ['path ' ].'/ ' .$ this ->getRelativePath ($ domain , $ messages ->getLocale ());
73+ if (!file_exists ($ fullpath )) {
74+ $ directory = \dirname ($ fullpath );
9075 if (!file_exists ($ directory ) && !@mkdir ($ directory , 0777 , true )) {
9176 throw new RuntimeException (sprintf ('Unable to create directory "%s". ' , $ directory ));
9277 }
9378 }
9479
95- if (file_exists ($ altPath )) {
96- // clear alternative translation file
97- file_put_contents ($ altPath , $ this ->formatCatalogue (new MessageCatalogue ($ messages ->getLocale ()), $ altDomain , $ options ));
80+ $ intlDomain = $ domain .MessageCatalogue::INTL_DOMAIN_SUFFIX ;
81+ $ intlMessages = $ messages ->all ($ intlDomain );
82+
83+ if ($ intlMessages ) {
84+ $ intlPath = $ options ['path ' ].'/ ' .$ this ->getRelativePath ($ intlDomain , $ messages ->getLocale ());
85+ file_put_contents($ intlPath , $ this ->formatCatalogue ($ messages , $ intlDomain , $ options ));
86+
87+ $ messages ->replace ([], $ intlDomain );
88+
89+ try {
90+ if ($ messages ->all ($ domain )) {
91+ file_put_contents ($ fullpath , $ this ->formatCatalogue ($ messages , $ domain , $ options ));
92+ }
93+ continue ;
94+ } finally {
95+ $ messages ->replace ($ intlMessages , $ intlDomain );
96+ }
9897 }
9998
100- file_put_contents ($ defaultPath , $ this ->formatCatalogue ($ messages , $ domain , $ options ));
99+ file_put_contents ($ fullpath , $ this ->formatCatalogue ($ messages , $ domain , $ options ));
101100 }
102101 }
103102
0 commit comments