From 60cc5142cefc39f840d6cde95dfc5c72e9f114a3 Mon Sep 17 00:00:00 2001 From: Niels Vanpachtenbeke <10651054+Nielsvanpach@users.noreply.github.com> Date: Mon, 29 Apr 2024 10:23:58 +0200 Subject: [PATCH] fix naming of translation files --- .../en/holidays.json | 0 src/Concerns/Translatable.php | 10 +++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) rename lang/{bosniaAndHerzegovina => bosnia-and-herzegovina}/en/holidays.json (100%) diff --git a/lang/bosniaAndHerzegovina/en/holidays.json b/lang/bosnia-and-herzegovina/en/holidays.json similarity index 100% rename from lang/bosniaAndHerzegovina/en/holidays.json rename to lang/bosnia-and-herzegovina/en/holidays.json diff --git a/src/Concerns/Translatable.php b/src/Concerns/Translatable.php index afd9f2084..3c13a6a1f 100644 --- a/src/Concerns/Translatable.php +++ b/src/Concerns/Translatable.php @@ -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)) { @@ -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) + ); + } }