https://github.com/outl1ne/nova-lang
This Laravel Nova package allows you to sort Nova resource's index view and assign locales to resources
https://github.com/outl1ne/nova-lang
laravel-nova laravel-nova-tool locale nova
Last synced: 3 months ago
JSON representation
This Laravel Nova package allows you to sort Nova resource's index view and assign locales to resources
- Host: GitHub
- URL: https://github.com/outl1ne/nova-lang
- Owner: outl1ne
- License: mit
- Created: 2019-10-25T10:11:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-01T12:22:08.000Z (7 months ago)
- Last Synced: 2025-02-14T22:05:12.943Z (4 months ago)
- Topics: laravel-nova, laravel-nova-tool, locale, nova
- Language: Vue
- Homepage:
- Size: 999 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Nova Lang
[Laravel Nova](https://nova.laravel.com) package that allows you to set localization of content.

## Installation
Install the package in a Laravel Nova project via Composer and run migrations:
```bash
# Install package
composer require optimistdigital/nova-lang
```Publish the `nova-lang` configuration file and edit it to your preference:
```bash
php artisan vendor:publish --provider="OptimistDigital\NovaLang\ToolServiceProvider" --tag="config"
```Register the tool with Nova in the `tools()` method of the `NovaServiceProvider`:
```php
// in app/Providers/NovaServiceProvider.phppublic function tools()
{
return [
// ...
new \OptimistDigital\NovaLang\NovaLang
];
}
```## Defining locales
```php
// in /config/nova-lang.php// ...
'locales' => [
'en' => 'English',
'et' => 'Estonian',
],// OR
'locales' => function () {
return Locale::all()->pluck('name', 'key');
},```
After defining locales in /config/nova-lang.php, you can use helper function.
```php
$locales = nova_lang_get_all_locales();//or you can use it in another package.
'locales' => nova_lang_get_all_locales(),
```## Usage
### Creating the field
```php
$fields[] = NovaLangField::make('Locale', 'locale');
```If you are using a translation package like nova-locale-field, you can also give
locale_parent_id. localeParentId has to be optainable through url query. Make sure you have defined locale_parent_id in your database.```php
$fields[] = NovaLangField::make('Locale', 'locale', 'locale_parent_id')
```### Sort resources by locale
```php
//Your resource file, where you have returned $fields array
public static function indexQuery(NovaRequest $request, $query)
{
$localeColumn = 'your_table_name' . 'locale'
$query->where(function ($subQuery) use ($localeColumn) {
$subQuery->where($localeColumn, nova_lang_get_active_locale())
->orWhereNotIn($localeColumn, array_keys(nova_lang_get_all_locales()));
});
return $query;
}
```## Credits
- [Kaspar Rosin](https://github.com/KasparRosin)
## License
Nova page manager is open-sourced software licensed under the [MIT license](LICENSE.md).