diff --git a/app/Locale/Models/StaticCountry.php b/app/Locale/Models/StaticCountry.php index 1567863d7..9594d1414 100644 --- a/app/Locale/Models/StaticCountry.php +++ b/app/Locale/Models/StaticCountry.php @@ -51,4 +51,9 @@ class StaticCountry extends Model 'phone_number_formatting' => 'array', 'currency_format' => 'array', ]; + + public function locales() + { + return $this->hasMany(StaticLocale::class); + } } diff --git a/app/Locale/Models/StaticLanguage.php b/app/Locale/Models/StaticLanguage.php index 7b2eda95d..476ee2bf8 100644 --- a/app/Locale/Models/StaticLanguage.php +++ b/app/Locale/Models/StaticLanguage.php @@ -31,4 +31,9 @@ class StaticLanguage extends Model protected $casts = [ 'exonyms' => 'array', ]; + + public function locales() + { + return $this->hasMany(StaticLocale::class); + } } diff --git a/app/Locale/Models/StaticLocale.php b/app/Locale/Models/StaticLocale.php new file mode 100644 index 000000000..604c4a72d --- /dev/null +++ b/app/Locale/Models/StaticLocale.php @@ -0,0 +1,36 @@ +belongsTo(StaticLanguage::class); + } + + public function country() + { + return $this->belongsTo(StaticCountry::class); + } + + protected $casts = []; +} diff --git a/app/Locale/Plugins/StaticLocalePlugin.php b/app/Locale/Plugins/StaticLocalePlugin.php new file mode 100644 index 000000000..d303065b8 --- /dev/null +++ b/app/Locale/Plugins/StaticLocalePlugin.php @@ -0,0 +1,37 @@ +resources([ + StaticLocaleResource::class, + ]); + } + + public function boot(Panel $panel): void + { + // + } + + public static function make(): static + { + return app(static::class); + } +} diff --git a/app/Locale/Presets/LocalePreset.php b/app/Locale/Presets/LocalePreset.php index 556be6445..4cafc3c5f 100644 --- a/app/Locale/Presets/LocalePreset.php +++ b/app/Locale/Presets/LocalePreset.php @@ -51,7 +51,7 @@ protected function initializePreset(): void label: 'language', description: 'Language to Locale', nullable: false, - relatedModel: \App\Locale\Locale\Models\StaticLanguage::class, + relatedModel: \App\Locale\Models\StaticLanguage::class, ), new Relationship( name: 'country', diff --git a/app/Locale/Resources/StaticCountryResource.php b/app/Locale/Resources/StaticCountryResource.php index b045b042b..a53ebf917 100644 --- a/app/Locale/Resources/StaticCountryResource.php +++ b/app/Locale/Resources/StaticCountryResource.php @@ -13,10 +13,7 @@ use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables\Columns\TextColumn; -use Filament\Tables\Filters\Filter; -use Filament\Tables\Filters\SelectFilter; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; use Moox\Core\Traits\Base\BaseInResource; use Moox\Core\Traits\Simple\SingleSimpleInResource; @@ -68,57 +65,57 @@ public static function form(Form $form): Form Section::make() ->schema([ TextInput::make('alpha2') - ->label('Alpha-2 Code') + ->label(__('locale.alpha2')) ->maxLength(3)->required(), TextInput::make('alpha3_b') - ->label('Alpha-3 Code (B)') + ->label(__('locale.alpha3_b')) ->maxLength(3)->nullable(), TextInput::make('alpha3_t') - ->label('Alpha-3 Code (T)') + ->label(__('locale.alpha3_t')) ->maxLength(3)->nullable(), TextInput::make('common_name') - ->label('Common Name') + ->label(__('locale.common_name')) ->maxLength(255)->required(), TextInput::make('native_name') - ->label('Native Name') + ->label(__('locale.native_name')) ->maxLength(255)->nullable(), KeyValue::make('exonyms') - ->label('Exonyms'), + ->label(__('locale.exonyms')), TextInput::make('calling_code') - ->label('Calling Code') + ->label(__('entities/static-country.calling_code')) ->numeric()->maxValue(100), TextInput::make('capital') - ->label('Capital') + ->label(__('entities/static-country.capital')) ->maxLength(255)->nullable(), TextInput::make('population') - ->label('Population') + ->label(__('entities/static-country.population')) ->maxLength(255)->nullable(), TextInput::make('area') - ->label('Area') + ->label(__('entities/static-country.area')) ->maxLength(255)->nullable(), KeyValue::make('links') - ->label('Links'), + ->label(__('entities/static-country.links')), KeyValue::make('tlds') - ->label('TLDs'), + ->label(__('entities/static-country.tlds')), KeyValue::make('membership') - ->label('Membership'), + ->label(__('entities/static-country.membership')), KeyValue::make('embargo_data') - ->label('Embargo Data'), + ->label(__('entities/static-country.embargo_data')), KeyValue::make('address_format') - ->label('Address Format'), + ->label(__('entities/static-country.address_format')), TextInput::make('postal_code_regex') - ->label('Postal Code Regex') + ->label(__('entities/static-country.postal_code_regex')) ->maxLength(255)->nullable(), TextInput::make('dialing_prefix') - ->label('Dialing Prefix') + ->label(__('entities/static-country.dialing_prefix')) ->maxLength(10)->nullable(), KeyValue::make('phone_number_formatting') - ->label('Phone Number Formatting'), + ->label(__('entities/static-country.phone_number_formatting')), TextInput::make('date_format') - ->label('Date Format') + ->label(__('entities/static-country.date_format')) ->maxLength(10)->required(), KeyValue::make('currency_format') - ->label('Currency Format'), + ->label(__('entities/static-country.currency_format')), ]), ]) ->columnSpan(['lg' => 2]), @@ -131,23 +128,20 @@ public static function form(Form $form): Form Section::make('') ->schema([ Select::make('region') - ->label('Region') - ->placeholder(__('core::core.type')) - ->options(['Africa' => 'Africa', 'Americas' => 'Americas', 'Asia' => 'Asia', 'Europe' => 'Europe', 'Oceania' => 'Oceania', 'Antarctica' => 'Antarctica']), + ->label(__('entities/static-country.region')) + ->options(__('entities/static-country.region_options')), ]), Section::make('') ->schema([ Select::make('subregion') - ->label('Subregion') - ->placeholder(__('core::core.type')) - ->options(['Northern Africa' => 'Northern Africa', 'Sub-Saharan Africa' => 'Sub-Saharan Africa', 'Eastern Africa' => 'Eastern Africa', 'Middle Africa' => 'Middle Africa', 'Southern Africa' => 'Southern Africa', 'Western Africa' => 'Western Africa', 'Latin America and the Caribbean' => 'Latin America and the Caribbean', 'Northern America' => 'Northern America', 'Caribbean' => 'Caribbean', 'Central America' => 'Central America', 'South America' => 'South America', 'Central Asia' => 'Central Asia', 'Eastern Asia' => 'Eastern Asia', 'South-Eastern Asia' => 'South-Eastern Asia', 'Southern Asia' => 'Southern Asia', 'Western Asia' => 'Western Asia', 'Eastern Europe' => 'Eastern Europe', 'Northern Europe' => 'Northern Europe', 'Southern Europe' => 'Southern Europe', 'Western Europe' => 'Western Europe', 'Australia and New Zealand' => 'Australia and New Zealand', 'Melanesia' => 'Melanesia', 'Micronesia' => 'Micronesia', 'Polynesia' => 'Polynesia']), + ->label(__('entities/static-country.subregion')) + ->options(__('entities/static-country.subregion_options')), ]), Section::make('') ->schema([ Select::make('embargo') - ->label('Embargo') - ->placeholder(__('core::core.type')) - ->options(['New' => 'New', 'Open' => 'Open', 'Pending' => 'Pending', 'Closed' => 'Closed']), + ->label(__('entities/static-country.embargo')) + ->options(__('entities/static-country.embargo_options')), ]), ]) ->columnSpan(['lg' => 1]), @@ -160,263 +154,25 @@ public static function table(Table $table): Table { return $table ->columns([ - TextColumn::make('alpha2'), - TextColumn::make('alpha3_b'), - TextColumn::make('alpha3_t'), - TextColumn::make('common_name'), - TextColumn::make('native_name'), - TextColumn::make('region')->sortable()->searchable()->toggleable(), - TextColumn::make('subregion')->sortable()->searchable()->toggleable(), - TextColumn::make('capital'), - TextColumn::make('population'), - TextColumn::make('area'), - TextColumn::make('embargo')->sortable()->searchable()->toggleable(), - TextColumn::make('postal_code_regex'), - TextColumn::make('dialing_prefix'), - TextColumn::make('date_format'), + TextColumn::make('alpha2')->label(__('locale.alpha2')), + TextColumn::make('alpha3_b')->label(__('locale.alpha3_b')), + TextColumn::make('alpha3_t')->label(__('locale.alpha3_t')), + TextColumn::make('common_name')->label(__('locale.common_name')), + TextColumn::make('native_name')->label(__('locale.native_name')), + TextColumn::make('region')->sortable()->searchable()->toggleable()->label(__('entities/static-country.region')), + TextColumn::make('subregion')->sortable()->searchable()->toggleable()->label(__('entities/static-country.subregion')), + TextColumn::make('capital')->label(__('entities/static-country.capital')), + TextColumn::make('population')->label(__('entities/static-country.population')), + TextColumn::make('area')->label(__('entities/static-country.area')), + TextColumn::make('embargo')->sortable()->searchable()->toggleable()->label(__('entities/static-country.embargo')), + TextColumn::make('postal_code_regex')->label(__('entities/static-country.postal_code_regex')), + TextColumn::make('dialing_prefix')->label(__('entities/static-country.dialing_prefix')), + TextColumn::make('date_format')->label(__('entities/static-country.date_format')), ]) ->defaultSort('id', 'desc') ->actions([...static::getTableActions()]) ->bulkActions([...static::getBulkActions()]) - ->filters([ - Filter::make('alpha2') - ->form([ - TextInput::make('alpha2') - ->label('Alpha-2 Code') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['alpha2'], - fn (Builder $query, $value): Builder => $query->where('alpha2', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['alpha2']) { - return null; - } - - return 'Alpha-2 Code: '.$data['alpha2']; - }), - Filter::make('alpha3_b') - ->form([ - TextInput::make('alpha3_b') - ->label('Alpha-3 Code (B)') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['alpha3_b'], - fn (Builder $query, $value): Builder => $query->where('alpha3_b', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['alpha3_b']) { - return null; - } - - return 'Alpha-3 Code (B): '.$data['alpha3_b']; - }), - Filter::make('alpha3_t') - ->form([ - TextInput::make('alpha3_t') - ->label('Alpha-3 Code (T)') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['alpha3_t'], - fn (Builder $query, $value): Builder => $query->where('alpha3_t', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['alpha3_t']) { - return null; - } - - return 'Alpha-3 Code (T): '.$data['alpha3_t']; - }), - Filter::make('common_name') - ->form([ - TextInput::make('common_name') - ->label('Common Name') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['common_name'], - fn (Builder $query, $value): Builder => $query->where('common_name', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['common_name']) { - return null; - } - - return 'Common Name: '.$data['common_name']; - }), - Filter::make('native_name') - ->form([ - TextInput::make('native_name') - ->label('Native Name') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['native_name'], - fn (Builder $query, $value): Builder => $query->where('native_name', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['native_name']) { - return null; - } - - return 'Native Name: '.$data['native_name']; - }), - Filter::make('has_exonyms') - ->query(fn ($query) => $query->whereNotNull('exonyms')), - SelectFilter::make('region') - ->label('Region') - ->placeholder(__('core::core.filter').' Region') - ->options(['Africa' => 'Africa', 'Americas' => 'Americas', 'Asia' => 'Asia', 'Europe' => 'Europe', 'Oceania' => 'Oceania', 'Antarctica' => 'Antarctica']), - SelectFilter::make('subregion') - ->label('Subregion') - ->placeholder(__('core::core.filter').' Subregion') - ->options(['Northern Africa' => 'Northern Africa', 'Sub-Saharan Africa' => 'Sub-Saharan Africa', 'Eastern Africa' => 'Eastern Africa', 'Middle Africa' => 'Middle Africa', 'Southern Africa' => 'Southern Africa', 'Western Africa' => 'Western Africa', 'Latin America and the Caribbean' => 'Latin America and the Caribbean', 'Northern America' => 'Northern America', 'Caribbean' => 'Caribbean', 'Central America' => 'Central America', 'South America' => 'South America', 'Central Asia' => 'Central Asia', 'Eastern Asia' => 'Eastern Asia', 'South-Eastern Asia' => 'South-Eastern Asia', 'Southern Asia' => 'Southern Asia', 'Western Asia' => 'Western Asia', 'Eastern Europe' => 'Eastern Europe', 'Northern Europe' => 'Northern Europe', 'Southern Europe' => 'Southern Europe', 'Western Europe' => 'Western Europe', 'Australia and New Zealand' => 'Australia and New Zealand', 'Melanesia' => 'Melanesia', 'Micronesia' => 'Micronesia', 'Polynesia' => 'Polynesia']), - Filter::make('capital') - ->form([ - TextInput::make('capital') - ->label('Capital') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['capital'], - fn (Builder $query, $value): Builder => $query->where('capital', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['capital']) { - return null; - } - - return 'Capital: '.$data['capital']; - }), - Filter::make('population') - ->form([ - TextInput::make('population') - ->label('Population') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['population'], - fn (Builder $query, $value): Builder => $query->where('population', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['population']) { - return null; - } - - return 'Population: '.$data['population']; - }), - Filter::make('area') - ->form([ - TextInput::make('area') - ->label('Area') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['area'], - fn (Builder $query, $value): Builder => $query->where('area', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['area']) { - return null; - } - - return 'Area: '.$data['area']; - }), - Filter::make('has_links') - ->query(fn ($query) => $query->whereNotNull('links')), - Filter::make('has_tlds') - ->query(fn ($query) => $query->whereNotNull('tlds')), - Filter::make('has_membership') - ->query(fn ($query) => $query->whereNotNull('membership')), - SelectFilter::make('embargo') - ->label('Embargo') - ->placeholder(__('core::core.filter').' Embargo') - ->options(['New' => 'New', 'Open' => 'Open', 'Pending' => 'Pending', 'Closed' => 'Closed']), - Filter::make('has_embargo_data') - ->query(fn ($query) => $query->whereNotNull('embargo_data')), - Filter::make('has_address_format') - ->query(fn ($query) => $query->whereNotNull('address_format')), - Filter::make('postal_code_regex') - ->form([ - TextInput::make('postal_code_regex') - ->label('Postal Code Regex') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['postal_code_regex'], - fn (Builder $query, $value): Builder => $query->where('postal_code_regex', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['postal_code_regex']) { - return null; - } - - return 'Postal Code Regex: '.$data['postal_code_regex']; - }), - Filter::make('dialing_prefix') - ->form([ - TextInput::make('dialing_prefix') - ->label('Dialing Prefix') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['dialing_prefix'], - fn (Builder $query, $value): Builder => $query->where('dialing_prefix', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['dialing_prefix']) { - return null; - } - - return 'Dialing Prefix: '.$data['dialing_prefix']; - }), - Filter::make('has_phone_number_formatting') - ->query(fn ($query) => $query->whereNotNull('phone_number_formatting')), - Filter::make('date_format') - ->form([ - TextInput::make('date_format') - ->label('Date Format') - ->placeholder(__('core::core.search')), - ]) - ->query(function (Builder $query, array $data): Builder { - return $query->when( - $data['date_format'], - fn (Builder $query, $value): Builder => $query->where('date_format', 'like', "%{$value}%"), - ); - }) - ->indicateUsing(function (array $data): ?string { - if (! $data['date_format']) { - return null; - } - - return 'Date Format: '.$data['date_format']; - }), - Filter::make('has_currency_format') - ->query(fn ($query) => $query->whereNotNull('currency_format')), - ]); + ->filters([]); } public static function getPages(): array diff --git a/app/Locale/Resources/StaticLanguageResource.php b/app/Locale/Resources/StaticLanguageResource.php index 9ff790f68..08c30b6dc 100644 --- a/app/Locale/Resources/StaticLanguageResource.php +++ b/app/Locale/Resources/StaticLanguageResource.php @@ -50,12 +50,12 @@ public static function getBreadcrumb(): string public static function getNavigationGroup(): ?string { - return config('app.navigation_group'); + return config('static-language.navigation_group'); } public static function getNavigationSort(): ?int { - return config('navigation_sort') + 1; + return config('static-language.navigation_sort') + 1; } public static function form(Form $form): Form @@ -68,22 +68,22 @@ public static function form(Form $form): Form Section::make() ->schema([ TextInput::make('alpha2') - ->label('Alpha-2 Code') + ->label(__('locale.alpha2')) ->maxLength(255)->required(), TextInput::make('alpha3_b') - ->label('Alpha-3 Bibliographic Code') + ->label(__('locale.alpha3_b')) ->maxLength(255)->nullable(), TextInput::make('alpha3_t') - ->label('Alpha-3 Terminology Code') + ->label(__('locale.alpha3_t')) ->maxLength(255)->nullable(), TextInput::make('common_name') - ->label('Common Name') + ->label(__('locale.common_name')) ->maxLength(255)->required(), TextInput::make('native_name') - ->label('Native Name') + ->label(__('locale.native_name')) ->maxLength(255)->nullable(), KeyValue::make('exonyms') - ->label('Exonyms'), + ->label(__('locale.exonyms')), ]), ]) ->columnSpan(['lg' => 2]), @@ -96,17 +96,15 @@ public static function form(Form $form): Form Section::make('') ->schema([ Select::make('script') - ->label('Script') - ->placeholder(__('core::core.type')) - ->options(['Latin' => 'Latin', 'Cyrillic' => 'Cyrillic', 'Arabic' => 'Arabic', 'Devanagari' => 'Devanagari', 'Other' => 'Other']) + ->label(__('entities/static-language.script')) + ->options(__('entities/static-language.script_options')) ->required(), ]), Section::make('') ->schema([ Select::make('direction') - ->label('Direction') - ->placeholder(__('core::core.type')) - ->options(['LTR' => 'LTR', 'RTL' => 'RTL']) + ->label(__('entities/static-language.direction')) + ->options(__('entities/static-language.direction_options')) ->required(), ]), ]) @@ -141,7 +139,7 @@ public static function table(Table $table): Table ->query(function (Builder $query, array $data): Builder { return $query->when( $data['alpha2'], - fn (Builder $query, $value): Builder => $query->where('alpha2', 'like', "%{$value}%"), + fn(Builder $query, $value): Builder => $query->where('alpha2', 'like', "%{$value}%"), ); }) ->indicateUsing(function (array $data): ?string { @@ -149,7 +147,7 @@ public static function table(Table $table): Table return null; } - return 'Alpha-2 Code: '.$data['alpha2']; + return 'Alpha-2 Code: ' . $data['alpha2']; }), Filter::make('alpha3_b') ->form([ @@ -160,7 +158,7 @@ public static function table(Table $table): Table ->query(function (Builder $query, array $data): Builder { return $query->when( $data['alpha3_b'], - fn (Builder $query, $value): Builder => $query->where('alpha3_b', 'like', "%{$value}%"), + fn(Builder $query, $value): Builder => $query->where('alpha3_b', 'like', "%{$value}%"), ); }) ->indicateUsing(function (array $data): ?string { @@ -168,7 +166,7 @@ public static function table(Table $table): Table return null; } - return 'Alpha-3 Bibliographic Code: '.$data['alpha3_b']; + return 'Alpha-3 Bibliographic Code: ' . $data['alpha3_b']; }), Filter::make('alpha3_t') ->form([ @@ -179,7 +177,7 @@ public static function table(Table $table): Table ->query(function (Builder $query, array $data): Builder { return $query->when( $data['alpha3_t'], - fn (Builder $query, $value): Builder => $query->where('alpha3_t', 'like', "%{$value}%"), + fn(Builder $query, $value): Builder => $query->where('alpha3_t', 'like', "%{$value}%"), ); }) ->indicateUsing(function (array $data): ?string { @@ -187,7 +185,7 @@ public static function table(Table $table): Table return null; } - return 'Alpha-3 Terminology Code: '.$data['alpha3_t']; + return 'Alpha-3 Terminology Code: ' . $data['alpha3_t']; }), Filter::make('common_name') ->form([ @@ -198,7 +196,7 @@ public static function table(Table $table): Table ->query(function (Builder $query, array $data): Builder { return $query->when( $data['common_name'], - fn (Builder $query, $value): Builder => $query->where('common_name', 'like', "%{$value}%"), + fn(Builder $query, $value): Builder => $query->where('common_name', 'like', "%{$value}%"), ); }) ->indicateUsing(function (array $data): ?string { @@ -206,7 +204,7 @@ public static function table(Table $table): Table return null; } - return 'Common Name: '.$data['common_name']; + return 'Common Name: ' . $data['common_name']; }), Filter::make('native_name') ->form([ @@ -217,7 +215,7 @@ public static function table(Table $table): Table ->query(function (Builder $query, array $data): Builder { return $query->when( $data['native_name'], - fn (Builder $query, $value): Builder => $query->where('native_name', 'like', "%{$value}%"), + fn(Builder $query, $value): Builder => $query->where('native_name', 'like', "%{$value}%"), ); }) ->indicateUsing(function (array $data): ?string { @@ -225,15 +223,15 @@ public static function table(Table $table): Table return null; } - return 'Native Name: '.$data['native_name']; + return 'Native Name: ' . $data['native_name']; }), SelectFilter::make('script') ->label('Script') - ->placeholder(__('core::core.filter').' Script') + ->placeholder(__('core::core.filter') . ' Script') ->options(['Latin' => 'Latin', 'Cyrillic' => 'Cyrillic', 'Arabic' => 'Arabic', 'Devanagari' => 'Devanagari', 'Other' => 'Other']), SelectFilter::make('direction') ->label('Direction') - ->placeholder(__('core::core.filter').' Direction') + ->placeholder(__('core::core.filter') . ' Direction') ->options(['LTR' => 'LTR', 'RTL' => 'RTL']), ]); } diff --git a/app/Locale/Resources/StaticLocaleResource.php b/app/Locale/Resources/StaticLocaleResource.php new file mode 100644 index 000000000..ffb7f344a --- /dev/null +++ b/app/Locale/Resources/StaticLocaleResource.php @@ -0,0 +1,234 @@ +schema([ + Grid::make(2) + ->schema([ + Grid::make() + ->schema([ + Section::make() + ->schema([ + TextInput::make('id') + ->label(__('entities/static-locale.id')) + ->maxLength(255)->required(), + Select::make('language_id') + ->label(__('entities/static-locale.language')) + ->relationship('language', 'common_name') + ->searchable() + ->preload()->required(), + Select::make('country_id') + ->label(__('entities/static-locale.country')) + ->relationship('country', 'common_name') + ->searchable() + ->preload()->required(), + TextInput::make('locale') + ->label(__('entities/static-locale.locale')) + ->maxLength(255)->required(), + TextInput::make('name') + ->label(__('entities/static-locale.name')) + ->maxLength(255)->required(), + + ]), + ]) + ->columnSpan(['lg' => 2]), + Grid::make() + ->schema([ + Section::make() + ->schema([ + static::getFormActions(), + ]), + ]) + ->columnSpan(['lg' => 1]), + ]) + ->columns(['lg' => 3]), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + TextColumn::make('locale')->label(__('entities/static-locale.locale')), + TextColumn::make('name')->label(__('entities/static-locale.name'))->sortable()->searchable()->toggleable(), + TextColumn::make('language.common_name') + ->label(__('entities/static-language.common_name')) + ->sortable(), + TextColumn::make('country.common_name') + ->label(__('entities/static-country.common_name')) + ->sortable(), + ]) + ->defaultSort('id', 'desc') + ->actions([...static::getTableActions()]) + ->bulkActions([...static::getBulkActions()]) + ->filters([ + Filter::make('id') + ->form([ + TextInput::make('id') + ->label(__('entities/static-locale.id')) + ->placeholder(__('core::core.search')), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query->when( + $data['id'], + fn(Builder $query, $value): Builder => $query->where('id', 'like', "%{$value}%"), + ); + }) + ->indicateUsing(function (array $data): ?string { + if (! $data['id']) { + return null; + } + + return 'ID: ' . $data['id']; + }), + Filter::make('language_id') + ->form([ + TextInput::make('language_id') + ->label(__('entities/static-locale.language_id')) + ->placeholder(__('core::core.search')), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query->when( + $data['language_id'], + fn(Builder $query, $value): Builder => $query->where('language_id', 'like', "%{$value}%"), + ); + }) + ->indicateUsing(function (array $data): ?string { + if (! $data['language_id']) { + return null; + } + + return 'Language ID: ' . $data['language_id']; + }), + Filter::make('country_id') + ->form([ + TextInput::make('country_id') + ->label(__('entities/static-locale.country_id')) + ->placeholder(__('core::core.search')), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query->when( + $data['country_id'], + fn(Builder $query, $value): Builder => $query->where('country_id', 'like', "%{$value}%"), + ); + }) + ->indicateUsing(function (array $data): ?string { + if (! $data['country_id']) { + return null; + } + + return 'Country ID: ' . $data['country_id']; + }), + Filter::make('locale') + ->form([ + TextInput::make('locale') + ->label(__('entities/static-locale.locale')) + ->placeholder(__('core::core.search')), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query->when( + $data['locale'], + fn(Builder $query, $value): Builder => $query->where('locale', 'like', "%{$value}%"), + ); + }) + ->indicateUsing(function (array $data): ?string { + if (! $data['locale']) { + return null; + } + + return 'Locale: ' . $data['locale']; + }), + Filter::make('name') + ->form([ + TextInput::make('name') + ->label('Name') + ->placeholder(__('core::core.search')), + ]) + ->query(function (Builder $query, array $data): Builder { + return $query->when( + $data['name'], + fn(Builder $query, $value): Builder => $query->where('name', 'like', "%{$value}%"), + ); + }) + ->indicateUsing(function (array $data): ?string { + if (! $data['name']) { + return null; + } + + return 'Name: ' . $data['name']; + }), + SelectFilter::make('language') + ->relationship('language', 'common_name'), + SelectFilter::make('country') + ->relationship('country', 'common_name'), + ]); + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListStaticLocales::route('/'), + 'create' => Pages\CreateStaticLocale::route('/create'), + 'edit' => Pages\EditStaticLocale::route('/{record}/edit'), + 'view' => Pages\ViewStaticLocale::route('/{record}'), + ]; + } +} diff --git a/app/Locale/Resources/StaticLocaleResource/Pages/CreateStaticLocale.php b/app/Locale/Resources/StaticLocaleResource/Pages/CreateStaticLocale.php new file mode 100644 index 000000000..0d0db63a8 --- /dev/null +++ b/app/Locale/Resources/StaticLocaleResource/Pages/CreateStaticLocale.php @@ -0,0 +1,16 @@ +mountTabsInListPage(); + } + + public function getTabs(): array + { + return $this->getDynamicTabs('entities.static-locale.tabs', \App\Locale\Models\StaticLocale::class); + } +} diff --git a/app/Locale/Resources/StaticLocaleResource/Pages/ViewStaticLocale.php b/app/Locale/Resources/StaticLocaleResource/Pages/ViewStaticLocale.php new file mode 100644 index 000000000..7da7befb6 --- /dev/null +++ b/app/Locale/Resources/StaticLocaleResource/Pages/ViewStaticLocale.php @@ -0,0 +1,16 @@ + 'trans//entities/static-locale.static-locale', + 'plural' => 'trans//entities/static-locale.static-locales', + 'tabs' => [ + 'all' => [ + 'label' => 'trans//core::core.all', + 'icon' => 'gmdi-filter-list', + 'query' => [ + ], + ], + ], + 'relations' => [], + 'taxonomies' => [], +]; diff --git a/config/static-country.php b/config/static-country.php index fb18adb31..a319a65a0 100644 --- a/config/static-country.php +++ b/config/static-country.php @@ -1,8 +1,8 @@ 'trans//entities/static-country.static-country', - 'plural' => 'trans//entities/static-country.static-countries', + 'single' => 'trans//entities/static-country.static_country', + 'plural' => 'trans//entities/static-country.static_countries', 'tabs' => [ 'all' => [ 'label' => 'trans//core::core.all', diff --git a/config/static-language.php b/config/static-language.php index f895d4bf4..77583d9b9 100644 --- a/config/static-language.php +++ b/config/static-language.php @@ -1,14 +1,13 @@ 'trans//entities/static-language.static-language', - 'plural' => 'trans//entities/static-language.static-languages', + 'single' => 'trans//entities/static-language.static_language', + 'plural' => 'trans//entities/static-language.static_languages', 'tabs' => [ 'all' => [ 'label' => 'trans//core::core.all', 'icon' => 'gmdi-filter-list', - 'query' => [ - ], + 'query' => [], ], '0' => [ 'label' => 'LTR', diff --git a/config/static-locale.php b/config/static-locale.php new file mode 100644 index 000000000..a949ae50d --- /dev/null +++ b/config/static-locale.php @@ -0,0 +1,15 @@ + 'trans//entities/static-locale.static_locale', + 'plural' => 'trans//entities/static-locale.static_locales', + 'tabs' => [ + 'all' => [ + 'label' => 'trans//core::core.all', + 'icon' => 'gmdi-filter-list', + 'query' => [], + ], + ], + 'relations' => [], + 'taxonomies' => [], +]; diff --git a/database/migrations/2025_01_07_074611_create_static_locales_table.php b/database/migrations/2025_01_07_074611_create_static_locales_table.php new file mode 100644 index 000000000..86d4db0ff --- /dev/null +++ b/database/migrations/2025_01_07_074611_create_static_locales_table.php @@ -0,0 +1,32 @@ +id(); + $table->foreignId('language_id')->constrained('static_languages')->onDelete('cascade'); + $table->foreignId('country_id')->constrained('static_countries')->onDelete('cascade'); + $table->string('locale', 5); + $table->string('name'); + $table->boolean('is_official_language')->default(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('static_locales'); + } +}; diff --git a/database/seeders/StaticLocaleSeeder.php b/database/seeders/StaticLocaleSeeder.php new file mode 100644 index 000000000..8f19c3b73 --- /dev/null +++ b/database/seeders/StaticLocaleSeeder.php @@ -0,0 +1,29 @@ + 'en-US', + 'name' => 'English (United States)', + 'language_id' => \App\Locale\Models\StaticLanguage::where('alpha2', 'en')->first()->id, + 'country_id' => \App\Locale\Models\StaticCountry::where('alpha2', 'US')->first()->id, + ]); + + \App\Locale\Models\StaticLocale::create([ + 'locale' => 'fr-FR', + 'name' => 'French (France)', + 'language_id' => \App\Locale\Models\StaticLanguage::where('alpha2', 'fr')->first()->id, + 'country_id' => \App\Locale\Models\StaticCountry::where('alpha2', 'FR')->first()->id, + ]); + } +} diff --git a/lang/en/entities/static-country.php b/lang/en/entities/static-country.php new file mode 100644 index 000000000..d9a5d6dc8 --- /dev/null +++ b/lang/en/entities/static-country.php @@ -0,0 +1,27 @@ + 'Static Country', + 'static_countries' => 'Static Countries', + 'region' => 'Region', + 'subregion' => 'Subregion', + 'capital' => 'Capital', + 'population' => 'Population', + 'area' => 'Area', + 'embargo' => 'Embargo', + 'postal_code_regex' => 'Postal Code Regex', + 'dialing_prefix' => 'Dialing Prefix', + 'calling_code' => 'Calling Code', + 'date_format' => 'Date Format', + 'region_options' => ['Africa' => 'Africa', 'Americas' => 'Americas', 'Asia' => 'Asia', 'Europe' => 'Europe', 'Oceania' => 'Oceania', 'Antarctica' => 'Antarctica'], + 'subregion_options' => ['Northern Africa' => 'Northern Africa', 'Sub-Saharan Africa' => 'Sub-Saharan Africa', 'Eastern Africa' => 'Eastern Africa', 'Middle Africa' => 'Middle Africa', 'Southern Africa' => 'Southern Africa', 'Western Africa' => 'Western Africa', 'Latin America and the Caribbean' => 'Latin America and the Caribbean', 'Northern America' => 'Northern America', 'Caribbean' => 'Caribbean', 'Central America' => 'Central America', 'South America' => 'South America', 'Central Asia' => 'Central Asia', 'Eastern Asia' => 'Eastern Asia', 'South-Eastern Asia' => 'South-Eastern Asia', 'Southern Asia' => 'Southern Asia', 'Western Asia' => 'Western Asia', 'Eastern Europe' => 'Eastern Europe', 'Northern Europe' => 'Northern Europe', 'Southern Europe' => 'Southern Europe', 'Western Europe' => 'Western Europe', 'Australia and New Zealand' => 'Australia and New Zealand', 'Melanesia' => 'Melanesia', 'Micronesia' => 'Micronesia', 'Polynesia' => 'Polynesia'], + 'embargo_options' => ['New' => 'New', 'Open' => 'Open', 'Pending' => 'Pending', 'Closed' => 'Closed'], + 'calling_code' => 'Calling Code', + 'links' => 'Links', + 'tlds' => 'TLDs', + 'membership' => 'Membership', + 'embargo_data' => 'Embargo Data', + 'address_format' => 'Address Format', + 'phone_number_formatting' => 'Phone Number Formatting', + 'currency_format' => 'Currency Format', +]; diff --git a/lang/en/entities/static-language.php b/lang/en/entities/static-language.php new file mode 100644 index 000000000..5e15d5d15 --- /dev/null +++ b/lang/en/entities/static-language.php @@ -0,0 +1,11 @@ + 'Static Language', + 'static_languages' => 'Static Languages', + 'script' => 'Script', + 'script_options' => ['Latin' => 'Latin', 'Cyrillic' => 'Cyrillic', 'Arabic' => 'Arabic', 'Devanagari' => 'Devanagari', 'Other' => 'Other'], + 'direction' => 'Direction', + 'direction_options' => ['LTR' => 'LTR', 'RTL' => 'RTL'], + +]; diff --git a/lang/en/entities/static-locale.php b/lang/en/entities/static-locale.php new file mode 100644 index 000000000..eeac53c0e --- /dev/null +++ b/lang/en/entities/static-locale.php @@ -0,0 +1,16 @@ + 'Static Local', + 'static_locales' => 'Static Locales', + 'id' => 'id', + 'language' => 'Language', + 'language_id' => 'Language id', + 'country_id' => 'Country id', + 'country' => 'Country', + 'locale' => 'Locale', + 'name' => 'Name', + 'static_locale' => 'Static Locale', + 'static_locales' => 'Static Locales', + +]; diff --git a/lang/en/locale.php b/lang/en/locale.php new file mode 100644 index 000000000..1cd5b1252 --- /dev/null +++ b/lang/en/locale.php @@ -0,0 +1,11 @@ + + 'Alpha-2 Code', + 'alpha3_b' => 'Alpha-3 Bibliographic Code', + 'alpha3_t' => 'Alpha-3 Terminology Code', + 'exonyms' => 'Exonyms', + 'common_name' => 'Common Name', + 'native_name' => 'Native Name', +]; diff --git a/resources/lang/en/entities/static-country.php b/resources/lang/en/entities/static-country.php deleted file mode 100644 index 66dd45a98..000000000 --- a/resources/lang/en/entities/static-country.php +++ /dev/null @@ -1,6 +0,0 @@ - 'Static Country', - 'static-countries' => 'Static Countries', -]; diff --git a/resources/lang/en/entities/static-language.php b/resources/lang/en/entities/static-language.php deleted file mode 100644 index 466b7eefa..000000000 --- a/resources/lang/en/entities/static-language.php +++ /dev/null @@ -1,6 +0,0 @@ - 'Static Language', - 'static-languages' => 'Static Languages', -];