I would ask you if the following text translation management can be feasible or not in Laravel. I know that the best practice tell us to create a corresponding text table but for some reason I would try to keep these translation only in the json file.
Let say we have a table "soil_type", where each row define some property/values of a kind of soil. This is not a table that will be edited by the user. It is a "fixed" table used just for backend logic. And it will not need to be changed/adapted.
I will have:
ID
Translation key
value 1
value 2
etc etc
My intention is to put in this table the translation key of each record. When i want to echo or use this translation I will pass a variable e not a string to the various functions used for managing translation:
$trans_key = 'Sand'; //actually is retrieved from database.
echo __($trans_key);
@Francesco I've done something like this in the past. I ended up just putting a get method on the model. Then you can use it like normal and it will always be in the correct locale.
Example:
// db
Types
id | name
// model
class Type extends Model
{
public function getNameAttribute()
{
return __($this->name);
}
}
The name field would be the name in my default launguage (english). Which would end up being the translation key if you are using the translation strings helper __('Tree'). You would still need to set the apps locale somewhere App::setLocale('fr'), like in a route group or middleware.