Skip to content

Commit

Permalink
feat: just look up the json translation file by the given locale
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwjn committed Feb 25, 2025
1 parent d0da09e commit 9186ef4
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/LaravelTranslationsSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,11 @@ public function getTranslationsForLocale(string $locale): array
}
}

// Then also look for a JSON file with the same name as the locale.
// From the locale (aa_BB), it first tries to find a JSON file with the BB part, then with the aa part.
$jsonParts = explode('_', $locale);
foreach ([$locale, ...array_reverse($jsonParts)] as $part) {
$filename = strtolower($part) . '.json';
$jsonPath = lang_path($filename);

if (File::exists($jsonPath)) {
$json = File::get($jsonPath);
$strings['json'] = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
ksort($strings['json'], SORT_STRING | SORT_FLAG_CASE);
break;
}
$jsonPath = lang_path("$locale.json");
if (File::exists($jsonPath)) {
$json = File::get($jsonPath);
$strings['json'] = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
ksort($strings['json'], SORT_STRING | SORT_FLAG_CASE);
}

return $strings;
Expand Down

0 comments on commit 9186ef4

Please sign in to comment.