Dynamically translate labels using configureUsing by adding a new translatable label

I am in the process of translating an application into Greek. The translation is straightforward for most parts, but problems arise when translating labels that reference a model. For instance, in translating a create button, I typically have to visit each create button, assign a custom label alo ng with a page title, and then add these to the corresponding language JSON file. I attempted to dynamically change labels using configureUsing(), with code like $action->label("Create {$action->getModelLabel()}"). However, this approach fails because getModelLabel() cannot be used at that point, as the action is not yet initialised. Is there any way to accomplish this without going through each action, title, modal heading, since the code will be repeatable and will look bloated?
1 Reply
lazydog
lazydog7mo ago
In your ServiceProvider, boot method, you can add below codes. Then just load your json file in lang folder $components = [ Textentry::class, TextInput::class, Checkbox::class, CheckboxList::class, ... other components ] foreach ($components as $component) { $component::configureUsing(function ($c): void { $c->translateLabel(); }); }