33 lines
1.2 KiB
PHP
33 lines
1.2 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace Modules\Core\Localization\Models;
|
||
|
|
|
||
|
|
use Modules\Core\Localization\Services\LanguageCache;
|
||
|
|
use Spatie\TranslationLoader\LanguageLine as BaseLanguageLine;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Overrides the base package's locale fallback (config('app.fallback_locale'), a
|
||
|
|
* static .env value) with the store's actual default language — Lunar's
|
||
|
|
* `languages.default` flag, the same source LocaleMiddleware/LanguageCache already
|
||
|
|
* treat as the single source of truth for "this store's default language".
|
||
|
|
*
|
||
|
|
* Without this, changing the default language via the Filament Languages resource
|
||
|
|
* has no effect on which locale an untranslated storefront label falls back to —
|
||
|
|
* two disconnected "default locale" concepts silently drifting apart. Swapped in
|
||
|
|
* via config('translation-loader.model') (see LocalizationServiceProvider), the
|
||
|
|
* package's own documented extension point for this.
|
||
|
|
*/
|
||
|
|
class LanguageLine extends BaseLanguageLine
|
||
|
|
{
|
||
|
|
public function getTranslation(string $locale): ?string
|
||
|
|
{
|
||
|
|
if (isset($this->text[$locale])) {
|
||
|
|
return $this->text[$locale];
|
||
|
|
}
|
||
|
|
|
||
|
|
$fallback = app(LanguageCache::class)->defaultLocale();
|
||
|
|
|
||
|
|
return $fallback !== null ? ($this->text[$fallback] ?? null) : null;
|
||
|
|
}
|
||
|
|
}
|