This is a package for Laravel to handle localization and requires the package astrotomic/laravel-translatable.
These two commmands are all you need to install the package:
composer require moox/localization
php artisan localization:installCurious what the install command does? See manual installation below.
- Creates the
localizationstable (language/locale routing, admin/frontend visibility, fallback behaviour, per-row display settings). - Integrates with
astrotomic/laravel-translatableandmoox/core. - Provides a language selector for Filament (flags + display names) and a Livewire language switch component.
- Optional Localization Filament panel (
enable-panelin config).
How Moox builds display names and flag icons for each localization, and how the Filament toggles relate to each other.
| Place | Attribute | Purpose |
|---|---|---|
Admin language dropdown (lang-selector blade) |
display_name, display_flag |
Current language + list of alternatives |
| Localization index table | display_name, table_flag |
Overview of all locales |
| Translation columns (Draft, News, Media, …) | display_flag |
Per-locale flag in translation UI |
| Filament create/edit form | Toggles + use_country_icon |
Configure each localization |
The Livewire language-switch component currently shows language codes only (no flags). Use display_flag when adding flags there.
For Filament resources with translations (Draft, News, Category, Media, etc.):
@include('localization::lang-selector')Or register a render hook on your panel. The view loads active localizations (is_active_admin or is_active_frontend), shows display_flag and display_name on the trigger, and lists alternatives the same way. Pass locale_variant as the lang query parameter so the correct regional entry is selected.
Names and flags are configured independently:
display_name ← per-row use_native_names
per-row show_regional_variants
per-row use_country_translations
(+ when translations on: country label language = default localization)
display_flag ← per-row use_country_icon
(+ language-specific exceptions, see below)
Each localization can tune its own name/flag output. Translated country names (when enabled) always use the default localization language, not the content ?lang= switcher — so the dropdown stays stable (e.g. always „Deutschland“ if default is German).
Regional affects names only, not flags. Country vs language flags are controlled only by Country flag (use_country_icon).
| Column | Type | Default | Role |
|---|---|---|---|
locale_variant |
string | required | e.g. de_CH, en_US, fr_CH |
use_native_names |
boolean | true |
Native vs English language name (per row) |
show_regional_variants |
boolean | true |
Append country from locale in name (per row) |
use_country_translations |
boolean | true |
Translated country name in parentheses (per row; language = default localization) |
use_country_icon |
boolean | false |
Country vs language flag icon (per row) |
Built by Localization::getDisplayNameAttribute() using this row’s toggles. When country translations are enabled, the country label language comes from Localization::displayLanguageAlpha3() (default localization) — not ?lang=.
| On | Off |
|---|---|
StaticLanguage::native_name |
StaticLanguage::common_name (usually English) |
| Deutsch | German |
When on and locale_variant contains _ (e.g. de_CH), appends the country in parentheses:
| On | Off |
|---|---|
| Deutsch (Schweiz) | Deutsch |
| English (United States) | English |
No effect when the locale has no region suffix (de only).
Only when Regional is on. Turning Regional off also turns Country names off. Controls the country part in parentheses:
| On | Off |
|---|---|
Translated name from static_countries.translations |
StaticCountry::common_name |
| Deutsch (Schweiz) | Deutsch (Switzerland) |
| Native | Regional | Country names | Result |
|---|---|---|---|
| off | off | — | German |
| on | off | — | Deutsch |
| on | on | off | Deutsch (Switzerland) |
| on | on | on | Deutsch (Schweiz) |
Built by Localization::resolveFlagIcon(). display_flag and table_flag always use the same logic.
| Value | Behaviour for de_CH |
|---|---|
false (default) |
Language flag → flag-de |
true |
Country flag from locale suffix → flag-ch |
Country code = part after _ in locale_variant, lowercased. Icon is used only if it exists (flagExists()).
Always use their language-specific icon, regardless of use_country_icon:
ku, bo, eo, eu, cy, br, co, ar, aa
| locale_variant | use_country_icon |
Flag shown |
|---|---|---|
de_CH |
false |
DE |
it_CH |
false |
IT |
fr_CH |
false |
FR |
With use_country_icon on all three, all show CH—usually not desired for a multilingual Swiss site.
| Column label | Database column | Affects |
|---|---|---|
| Native | use_native_names |
Name |
| Regional | show_regional_variants |
Name |
| Country names | use_country_translations |
Name (parentheses) |
| Country flag | use_country_icon |
Flag icon |
use Moox\Localization\Models\Localization;
$localization = Localization::where('locale_variant', 'de_CH')->first();
$localization->display_name; // e.g. "Deutsch (Schweiz)"
$localization->display_flag; // e.g. "flag-de"
$localization->table_flag; // same as display_flag
$localization->show_regional_variants;
$localization->use_country_icon;| Scenario | Native | Regional | Country names | Country flag |
|---|---|---|---|---|
Swiss multilingual (de_CH, it_CH, fr_CH) |
on | on | on | off |
| Simple list, no region in UI | on | off | — | off |
| Emphasize country over language (rare) | on | on | on | on |
| File | Responsibility |
|---|---|
src/Models/Localization.php |
Names + flag resolution |
resources/views/lang-selector.blade.php |
Admin dropdown |
src/Filament/Resources/LocalizationResource.php |
Form and table toggles |
config/localization.php |
Filament labels, navigation, panel |
database/migrations/create_localizations_table.php.stub |
Schema |
Enable in config:
'enable-panel' => true,Panel URL: /localization
Relies on locales marked active for admin or frontend. Text codes only today.
changeLocale only accepts language codes that are active for the given context (frontend / backend) and redirects only to same-host or relative URLs (LocaleSwitcher).
Filament panel hook:
->renderHook(
\Filament\View\PanelsRenderHook::USER_MENU_BEFORE,
fn (): string => \Illuminate\Support\Facades\Blade::render('@livewire(\'language-switch\',[\'context\'=>\'backend\'])'),
)Blade:
@livewire('language-switch', ['context' => 'backend'])Moox Core features like Dynamic Tabs and Translatable Config. See the config file; Moox Core docs explain tabs.
php artisan vendor:publish --tag="localization-migrations"
php artisan migrate
php artisan vendor:publish --tag="localization-config"We require astrotomic/laravel-translatable.
See CHANGELOG.
See security policy.
MIT — see LICENSE.
