Skip to content

Commit 3515797

Browse files
Merge pull request #351 from Laravel-Lang/16.x
Fix for fix :)
2 parents e62d571 + 2b069d1 commit 3515797

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

src/Helpers/Arr.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,17 @@ protected function filter(array $source, array $target, bool $filter_keys = fals
3636
{
3737
return $filter_keys ? DragonArr::only($target, DragonArr::keys($source)) : $target;
3838
}
39+
40+
public function ksort(array $source): array
41+
{
42+
ksort($source);
43+
44+
foreach ($source as $key => &$value) {
45+
if (is_array($value)) {
46+
$value = $this->ksort($value);
47+
}
48+
}
49+
50+
return $source;
51+
}
3952
}

src/Processors/Processor.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ function () use ($directory, $plugins) {
7171
/** @var Plugin $plugin */
7272
foreach ($plugins as $plugin) {
7373
$this->collectKeys($directory, $plugin->files());
74+
$this->collectLocalizations($directory, $plugin->files());
7475
}
75-
76-
$this->collectLocalizations($directory);
7776
}
7877
);
7978
}
@@ -109,28 +108,34 @@ protected function collectKeys(string $directory, array $files): void
109108
foreach ($files as $source => $target) {
110109
$values = $this->filesystem->load($directory . '/source/' . $source);
111110

112-
$this->translation->setSource($directory, $target, $values);
111+
$this->translation->setSource($target, $values);
113112
}
114113
}
115114

116-
protected function collectLocalizations(string $directory): void
115+
protected function collectLocalizations(string $directory, array $files): void
117116
{
118-
foreach ($this->locales as $locale) {
119-
$locale = $this->fromAlias($locale?->value ?? $locale);
117+
foreach ($files as $filename) {
118+
$keys = array_keys($this->translation->getSource($filename));
120119

121-
$locale_alias = $this->toAlias($locale);
120+
foreach ($this->locales as $locale) {
121+
$locale = $this->fromAlias($locale?->value ?? $locale);
122122

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);
123+
$locale_alias = $this->toAlias($locale);
126124

127-
$values = $this->filesystem->load($main_path);
125+
foreach ($this->file_types as $type) {
126+
$main_path = $this->localeFilename($locale_alias, "$directory/locales/$locale/$type.json");
127+
$inline_path = $this->localeFilename($locale_alias, "$directory/locales/$locale/$type.json", true);
128128

129-
if ($main_path !== $inline_path && $this->config->hasInline()) {
130-
$values = $this->arr->merge($values, $this->filesystem->load($inline_path));
131-
}
129+
$values = $this->filesystem->load($main_path);
130+
131+
if ($main_path !== $inline_path && $this->config->hasInline()) {
132+
$values = $this->arr->merge($values, $this->filesystem->load($inline_path));
133+
}
134+
135+
$values = collect($values)->only($keys)->toArray();
132136

133-
$this->translation->setTranslations($directory, $locale_alias, $values);
137+
$this->translation->setTranslations($filename, $locale_alias, $values);
138+
}
134139
}
135140
}
136141
}

src/Resources/Translation.php

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ public function __construct(
3131
readonly protected Arr $arr = new Arr()
3232
) {}
3333

34-
public function setSource(string $namespace, string $filename, array $values): self
34+
public function getSource(string $filename): array
3535
{
36-
$this->source[$namespace][$filename] = $this->merge($this->source[$namespace][$filename] ?? [], $values);
36+
return $this->source[$filename] ?? [];
37+
}
38+
39+
public function setSource(string $filename, array $values): self
40+
{
41+
$this->source[$filename] = $this->merge($this->source[$filename] ?? [], $values);
3742

3843
return $this;
3944
}
@@ -52,27 +57,15 @@ public function toArray(): array
5257
{
5358
$result = [];
5459

55-
foreach (array_keys($this->source) as $namespace) {
56-
if (! isset($this->source[$namespace])) {
57-
continue;
58-
}
60+
foreach ($this->source as $filename => $keys) {
61+
foreach ($this->translations[$filename] ?? [] as $locale => $values) {
62+
$name = $this->resolveFilename($filename, $locale);
5963

60-
foreach ($this->source[$namespace] as $filename => $keys) {
61-
if (! isset($this->translations[$namespace])) {
62-
continue;
63-
}
64-
65-
foreach ($this->translations[$namespace] as $locale => $values) {
66-
$name = $this->resolveFilename($filename, $locale);
67-
68-
$result[$locale][$name] = $this->merge($keys, $values, true);
69-
}
64+
$result[$locale][$name] = $this->merge($keys, $values, true);
7065
}
7166
}
7267

73-
ksort($result);
74-
75-
return $result;
68+
return $this->arr->ksort($result);
7669
}
7770

7871
protected function resolveFilename(string $path, string $locale): string

0 commit comments

Comments
 (0)