Most field types can be made translatable. A field that is translatable, does not contain one value, but a value for each language defined in your project. When accessing that field in your code, the value of the currect active language will be returned automatically.
In a data table, translatable fields will get a separate column for every visible language. In the upper right corner, you can choose which languages are visible. The also applies when editing an entry: only the selected languages will be visible, and you can choose them with a dropdown in the upper right corner of the dialog.
If you change an existing field from non-translatable to translatable, the current value will be copied to every language.
If you change an existing field from translatable to non-translatable, the option Keep data from will appear. Only the data from the language you select will be kept in the database, and the rest will be deleted. Be careful when doing such operations, because this cannot be undone.
There are several places in Devisto where you can perform translations:
- Globally: in the language overview, click Translate in the upper right corner.
- Page: right-click a page and choose Translate Page. You can also check multiple pages and choose Translate in the action popup.
- Entry: right-click an entry in a table and choose Translate Entry. You can also check multiple entries and choose Translate in the action popup.
- Field: right-click a field and choose Translate Field.
- Mail: right-click a mail and choose Translate Mail.
In all cases, you can choose the source and destination language. Note that all values in the destination language will be overwritten, so be careful!
Be default, the values will just be copied. However, if you check Translate Text Fields, the values of text fields will be translated using Google Translate.
Because we use the spatie/laravel-translatable package, some magic happens behind the scenes to let you access translatable fields just like non-translatable fields:
// Assuming `title` is translatable, this will give you the title in the
// current active language
table('products')->first()->title;
// In Tinker, the first language is always active, but you can change it
app()->setLocale('en');
$product->first()->title; // English title
app()->setLocale('nl');
$product->first()->title; // Dutch title
// Alternative way to get a specific translation
$product->first()->getTranslation('title', 'nl');
// When querying data, arrow notation is needed
table('products')->where('title->nl', 'like', '%foo%');
table('products')->orderBy('title->nl');
// Or use our helper methods to query the current language
// (works even with non-translatable fields)
table('products')->whereTranslatable('title', 'like', '%foo%');
table('products')->orderByTranslatable('title');