3

Actually, I need to change the laravel nova action name like translate into different languages.

class PrintWithDetail extends Action
{
    use InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
        $id = '';
        //
        foreach ($models as $model) {
            $id = $model->id;
        }
        return Action::openInNewTab(route("print.work.order", [$id, 'type' => 'detail']));
    }

}

Above action show PrintWithDetail as name.

But, I need to change PrintWithDetail into dutch.

1 Answer 1

10

Override the public property $name

/**
 * The displayable name of the action.
 *
 * @var string
 */
public $name;

So in your example

class PrintWithDetail extends Action
{
    use InteractsWithQueue, Queueable, SerializesModels;

    public $name = "Print met detail";

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
        $id = '';

        foreach ($models as $model) {
            $id = $model->id;
        }
        return Action::openInNewTab(route("print.work.order", [$id, 'type' => 'detail']));
    }
}

You can see all what you can change in the class the action extends in nova/src/Actions/Action.php

Update

If you need the name localized in other languages, you may override the method name return a string from the Laravel __() helper method

/**
 * Get the displayable name of the action.
 *
 * @return string
 */
public function name()
{
    return __('Print with details');
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your time and effort. By the way, I also did it as same like you mentioned above.
@Saly can you tell me , how to change default prefix "Create/Update" that comes with CRUD?
How do we fetch relationships for names? like if it is a pivot table...
This works but it will also use the name as key for the action_events logging table making tracking difficult if you use multiple languages at the same time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.