@@ -67,37 +67,36 @@ public function dump(MessageCatalogue $messages, $options = [])
67
67
throw new InvalidArgumentException ('The file dumper needs a path option. ' );
68
68
}
69
69
70
- $ hasMessageFormatter = class_exists (\MessageFormatter::class);
71
-
72
70
// save a file for each domain
73
71
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 );
90
75
if (!file_exists ($ directory ) && !@mkdir ($ directory , 0777 , true)) {
91
76
throw new RuntimeException (sprintf ('Unable to create directory "%s". ' , $ directory ));
92
77
}
93
78
}
94
79
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
+ }
98
97
}
99
98
100
- file_put_contents ($ defaultPath , $ this ->formatCatalogue ($ messages , $ domain , $ options ));
99
+ file_put_contents ($ fullpath , $ this ->formatCatalogue ($ messages , $ domain , $ options ));
101
100
}
102
101
}
103
102
0 commit comments