Skip to content

Commit

Permalink
fix naming of translation files
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Apr 29, 2024
1 parent 7d93b35 commit 60cc514
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
File renamed without changes.
10 changes: 9 additions & 1 deletion src/Concerns/Translatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public function translate(string $country, string $name, ?string $locale = null)

$locale = $locale ?? $this->defaultLocale();

$countryName = strtolower($country);
$countryName = $this->toHyphenSeparated($country);

$filePath = __DIR__."/../../lang/{$countryName}/{$locale}/holidays.json";

if (file_exists($filePath)) {
Expand All @@ -32,4 +33,11 @@ public function translate(string $country, string $name, ?string $locale = null)

return $data[$name] ?? $name;
}

protected function toHyphenSeparated(string $text): string
{
return strtolower(
preg_replace('/(?<=\\w)(?=[A-Z])/', '-$1', $text)
);
}
}

0 comments on commit 60cc514

Please sign in to comment.