@@ -51,9 +51,9 @@ public function __construct(
51
51
readonly protected Config $ config ,
52
52
protected Manager $ filesystem = new Manager (),
53
53
protected ArrHelper $ arr = new ArrHelper (),
54
- protected Translation $ translation = new Translation (
55
- )
56
- ) { }
54
+ protected Translation $ translation = new Translation ()
55
+ ) {
56
+ }
57
57
58
58
public function prepare (): self
59
59
{
@@ -62,17 +62,20 @@ public function prepare(): self
62
62
63
63
public function collect (): self
64
64
{
65
+ $ this ->info ('Collecting translations... ' );
66
+
65
67
foreach ($ this ->plugins () as $ directory => $ plugins ) {
66
- $ this ->info ($ this ->config ->getPackageNameByPath ($ directory , Types::TypeClass));
68
+ $ this ->task (
69
+ $ this ->config ->getPackageNameByPath ($ directory , Types::TypeClass),
70
+ function () use ($ directory , $ plugins ) {
71
+ /** @var Plugin $plugin */
72
+ foreach ($ plugins as $ plugin ) {
73
+ $ this ->collectKeys ($ directory , $ plugin ->files ());
74
+ }
67
75
68
- $ this ->task ('Collect source ' , function () use ($ directory , $ plugins ) {
69
- /** @var Plugin $plugin */
70
- foreach ($ plugins as $ plugin ) {
71
- $ this ->collectKeys ($ directory , $ plugin ->files ());
76
+ $ this ->collectLocalizations ($ directory );
72
77
}
73
- });
74
-
75
- $ this ->collectLocalizations ($ directory );
78
+ );
76
79
}
77
80
78
81
return $ this ;
@@ -88,7 +91,7 @@ public function store(): void
88
91
$ path = $ this ->config ->langPath ($ filename );
89
92
90
93
$ values
91
- = $ this ->reset || ! File::exists ($ path )
94
+ = $ this ->reset || !File::exists ($ path )
92
95
? $ values
93
96
: $ this ->arr ->merge (
94
97
$ this ->filesystem ->load ($ path ),
@@ -106,7 +109,7 @@ protected function collectKeys(string $directory, array $files): void
106
109
foreach ($ files as $ source => $ target ) {
107
110
$ values = $ this ->filesystem ->load ($ directory . '/source/ ' . $ source );
108
111
109
- $ this ->translation ->setSource ($ target , $ values );
112
+ $ this ->translation ->setSource ($ directory , $ target , $ values );
110
113
}
111
114
}
112
115
@@ -117,20 +120,18 @@ protected function collectLocalizations(string $directory): void
117
120
118
121
$ locale_alias = $ this ->toAlias ($ locale );
119
122
120
- $ this ->task ('Collecting ' . $ locale , function () use ($ locale , $ locale_alias , $ directory ) {
121
- foreach ($ this ->file_types as $ type ) {
122
- $ main_path = $ this ->localeFilename ($ locale_alias , "$ directory/locales/ $ locale/ $ type.json " );
123
- $ inline_path = $ this ->localeFilename ($ locale_alias , "$ directory/locales/ $ locale/ $ type.json " , true );
123
+ foreach ($ this ->file_types as $ type ) {
124
+ $ main_path = $ this ->localeFilename ($ locale_alias , "$ directory/locales/ $ locale/ $ type.json " );
125
+ $ inline_path = $ this ->localeFilename ($ locale_alias , "$ directory/locales/ $ locale/ $ type.json " , true );
124
126
125
- $ values = $ this ->filesystem ->load ($ main_path );
127
+ $ values = $ this ->filesystem ->load ($ main_path );
126
128
127
- if ($ main_path !== $ inline_path && $ this ->config ->hasInline ()) {
128
- $ values = $ this ->arr ->merge ($ values , $ this ->filesystem ->load ($ inline_path ));
129
- }
130
-
131
- $ this ->translation ->setTranslations ($ locale_alias , $ values );
129
+ if ($ main_path !== $ inline_path && $ this ->config ->hasInline ()) {
130
+ $ values = $ this ->arr ->merge ($ values , $ this ->filesystem ->load ($ inline_path ));
132
131
}
133
- });
132
+
133
+ $ this ->translation ->setTranslations ($ directory , $ locale_alias , $ values );
134
+ }
134
135
}
135
136
}
136
137
0 commit comments