diff --git a/src/HasTranslations.php b/src/HasTranslations.php index feeb736..f18888f 100644 --- a/src/HasTranslations.php +++ b/src/HasTranslations.php @@ -88,8 +88,25 @@ public function getTranslation(string $key, string $locale, bool $useFallbackLoc if (is_null(self::getAttributeFromArray($baseKey))) { $translation = null; } else { - $translation = isset($translations[$normalizedLocale]) ? $translations[$normalizedLocale] : null; - $translation ??= ($translatableConfig->allowNullForTranslation) ? null : ''; + $rawValue = self::getAttributeFromArray($baseKey); + + if ( + $useFallbackLocale && + !is_null($rawValue) && + is_string($rawValue) && + is_null(json_decode($rawValue, true)) && + json_last_error() !== JSON_ERROR_NONE + ) { + $translation = $rawValue; + } else { + $translation = $translations[$normalizedLocale] ?? null; + + if ($translation === null && $useFallbackLocale && $locale !== $normalizedLocale) { + $translation = $translations[$locale] ?? null; + } + + $translation ??= ($translatableConfig->allowNullForTranslation) ? null : ''; + } } if ($isKeyMissingFromLocale && $translatableConfig->missingKeyCallback) {