Skip to content

Commit 3bd99b8

Browse files
committed
update localization config
1 parent cf9177f commit 3bd99b8

5 files changed

Lines changed: 33 additions & 24 deletions

File tree

config/inspirecms.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@
265265
],
266266
],
267267

268-
'available_locales' => [
269-
'en',
270-
'zh_CN',
271-
'zh_TW',
268+
'localization' => [
269+
'user_preferred_locales' => ['en','zh_CN','zh_TW'],
272270
],
273271
];

src/Base/Filament/Pages/Concerns/ProfilePageTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Illuminate\Support\Facades\Hash;
1313
use Illuminate\Validation\Rules\Password;
1414
use SolutionForest\InspireCms\Base\Enums\UserActivity;
15-
use SolutionForest\InspireCms\Facades\LocaleManifest;
15+
use SolutionForest\InspireCms\Facades\LocalizationManager;
1616
use SolutionForest\InspireCms\Filament\Forms\Components\UserRolePicker;
1717
use SolutionForest\InspireCms\Helpers\AuthHelper;
1818
use SolutionForest\InspireCms\Helpers\UIHelper;
@@ -121,7 +121,7 @@ protected function getPreferredLanguageFormComponent()
121121
return Forms\Components\Select::make('preferred_language')
122122
->label(__('inspirecms::resources/user.preferred_language.label'))
123123
->validationAttribute(__('inspirecms::resources/user.preferred_language.validation_attribute'))
124-
->options(LocaleManifest::selectOptions())
124+
->options(LocalizationManager::getUserPreferredLocaleLabels())
125125
->searchable()
126126
->required();
127127
}

src/Base/Manifests/LocaleManifest.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,36 @@
66

77
class LocaleManifest implements LocaleManifestInterface
88
{
9-
protected array $locales = [];
9+
protected array $userPreferredLocales = [];
1010

1111
public function __construct()
1212
{
13-
$this->locales = collect(InspireCmsConfig::get('available_locales', []))->mapWithKeys(fn ($locale) => [$locale => $locale])->all();
13+
$this->userPreferredLocales = collect(InspireCmsConfig::get('localization.user_preferred_locales', ['en','zh_CN','zh_TW']))
14+
->mapWithKeys(fn ($locale) => [$locale => $locale])
15+
->all();
1416
}
1517

16-
public function addLocale(string $locale): void
18+
public function addUserPreferredLocale(string $locale): void
1719
{
18-
$this->locales[$locale] = $locale;
20+
$this->userPreferredLocales[$locale] = $locale;
1921
}
2022

21-
public function getLocales(): array
23+
public function removeUserPreferredLocale(string $locale): void
2224
{
23-
return $this->locales;
25+
unset($this->userPreferredLocales[$locale]);
2426
}
2527

26-
public function selectOptions(?string $displayLocale = null): array
28+
public function getUserPreferredLocales(): array
2729
{
28-
return collect($this->locales)->mapWithKeys(fn ($locale) => [
29-
$locale => locale_get_display_name($locale, $displayLocale ?? app()->getLocale()),
30-
])->all();
30+
return $this->userPreferredLocales;
31+
}
32+
33+
public function getUserPreferredLocaleLabels(?string $displayLocale = null): array
34+
{
35+
return collect($this->getUserPreferredLocales())
36+
->mapWithKeys(fn ($locale) => [
37+
$locale => locale_get_display_name($locale, $displayLocale ?? app()->getLocale()),
38+
])
39+
->all();
3140
}
3241
}

src/Base/Manifests/LocaleManifestInterface.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
interface LocaleManifestInterface
66
{
7-
public function addLocale(string $locale): void;
7+
public function addUserPreferredLocale(string $locale): void;
88

9-
public function getLocales(): array;
9+
public function removeUserPreferredLocale(string $locale): void;
1010

11-
public function selectOptions(?string $displayLocale = null): array;
11+
public function getUserPreferredLocales(): array;
12+
13+
public function getUserPreferredLocaleLabels(?string $displayLocale = null): array;
1214
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
use SolutionForest\InspireCms\Base\Manifests\LocaleManifestInterface;
77

88
/**
9-
* @method static void addLocale(string $Locale)
10-
* @method static array getLocales()
11-
* @method static array selectOptions(?string $displayLocale = null)
12-
* @method static array getNavigation(string $category, ?string $locale = null)
9+
* @method static void addUserPreferredLocale(string $locale)
10+
* @method static void removeUserPreferredLocale(string $locale)
11+
* @method static array getUserPreferredLocales()
12+
* @method static array getUserPreferredLocaleLabels(?string $displayLocale = null)
1313
*
1414
* @see \SolutionForest\InspireCms\Base\Manifests\LocaleManifest
1515
*/
16-
class LocaleManifest extends Facade
16+
class LocalizationManager extends Facade
1717
{
1818
/**
1919
* {@inheritdoc}

0 commit comments

Comments
 (0)