Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions ru/recipes/translatable-field.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Поля для нескольких языков

Простой способ сделать любое поле поддерживающее несколько языков, без дополнительных пакетов
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В конце предложений желательно точки ставить


Подходит для Spatie laravel-translatable или если вы как они, храните все переводу в json поле,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Несвязное предложение получилось, "как они" это как кто? )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно что то вроде если вы предпочитаете хранить переводы в json

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как они - это как Spatie laravel-translatable
О них же шла речь

Но могу переписать

Copy link
Member

Choose a reason for hiding this comment

The 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
{
public static function make(
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);
});
}
}
```

Использовать так
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут двоеточие


```php
Translatable::make(
trans('admin.resource.title'),
'title',
Text::make(),
),
```