-
Notifications
You must be signed in to change notification settings - Fork 64
Create recipe translatable-field.md #996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Поля для нескольких языков | ||
|
|
||
| Простой способ сделать любое поле поддерживающее несколько языков, без дополнительных пакетов | ||
|
|
||
| Подходит для Spatie laravel-translatable или если вы как они, храните все переводу в json поле, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Несвязное предложение получилось, "как они" это как кто? )
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. можно что то вроде если вы предпочитаете хранить переводы в json
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Как они - это как Spatie laravel-translatable Но могу переписать
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Да давай и добавь точек) англ версию и в навигацию |
||
| такого вида: `{"ru": "Текст", "en": "Text"}` | ||
|
|
||
| ```php | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace App\MoonShine\Fields; | ||
|
|
||
| use Illuminate\Database\Eloquent\Model; | ||
| use MoonShine\Contracts\UI\FieldContract; | ||
| use MoonShine\UI\Fields\Json; | ||
|
|
||
| final readonly class Translatable | ||
lee-to marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| public static function make( | ||
lee-to marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| string $label, | ||
| string $column, | ||
| FieldContract $field | ||
| ): Json { | ||
| $locales = collect(moonshine()->getConfig()->getLocales()); | ||
|
|
||
| return Json::make($label, $column) | ||
| ->object() | ||
| ->fields( | ||
| $locales->map( | ||
| fn (string $locale) => (clone $field) | ||
| ->setLabel(\Str::upper($locale)) | ||
| ->setColumn($locale) | ||
| ) | ||
| ->all(), | ||
| ) | ||
| ->removeClass('space-elements') | ||
| ->class('flex gap-6') | ||
| ->changeFill(function (Model $data) use ($column) { | ||
| return $data->getRawOriginal($column); | ||
| }); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Использовать так | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут двоеточие |
||
|
|
||
| ```php | ||
| Translatable::make( | ||
| trans('admin.resource.title'), | ||
| 'title', | ||
| Text::make(), | ||
| ), | ||
| ``` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В конце предложений желательно точки ставить