如何更改Laravel-Nova动作名称?

时间:2019-11-08 10:56:16

标签: laravel laravel-nova

实际上,我需要更改laravel nova动作名称,例如将其翻译成不同的语言。

import utils.YearInterval;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Parser {
    private Pattern comicBegin = Pattern.compile("<h3><span id=\"0\\.E2\\.80\\.939\"></span>.*?</h3>", Pattern.MULTILINE | Pattern.DOTALL);
    private Pattern comicEnd = Pattern.compile("<h2><span class=\"mw-headline\" id=\"Anmerkung_zu_Trickfilmen_und_Comiczeichnern\">.*?</h2>", Pattern.MULTILINE | Pattern.DOTALL); 
    private Pattern comicEnum = Pattern.compile("<tr>.*?<td.*?>(?:<a.*?\">)?(.*?)(?:</a.*?>)?.*?</td>.*?<td>(?:<a.*?>)?(.*?)(?:</a>)?.*?</td></tr>", Pattern.MULTILINE | Pattern.DOTALL);  // Tried also this <tr>\\n<td.*?>(?:<a.*?">)?(.*?)(?:</a.*?>)?\\n</td>\\n<td>(?:<a.*?>)?(.*?)(?:</a>)?\\n</td></tr>
    private Scanner wikiComicFilmScanner = null;

    public static void main(String[] args) throws MalformedURLException, IOException {
        Path wikiComicFilmLocal = Paths.get("ressources/ListevonComicverfilmungen.html");
        Parser wp1 = new Parser("file:///" + wikiComicFilmLocal.toAbsolutePath());
        long start = System.currentTimeMillis();
        Map<String, Map<YearInterval, List<String>>> comicMap = wp1.contentToComicFilmsPerYear();
        System.out.println("Parsen ausgeführt in: " + (System.currentTimeMillis() - start) + "ms");
    }

    public Parser(String uri) throws MalformedURLException, IOException {
        wikiComicFilmScanner = new Scanner(new URL(uri).openStream(), "UTF-8");
    }


    public Map<String, Map<YearInterval, List<String>>> contentToComicFilmsPerYear() {
        Map<String, Map<YearInterval, List<String>>> comicMap = new HashMap<>();
        wikiComicFilmScanner.useDelimiter(comicBegin);
        if (wikiComicFilmScanner.hasNext()) {
            wikiComicFilmScanner.next();
        }
        wikiComicFilmScanner.useDelimiter(comicEnd);
        if (wikiComicFilmScanner.hasNext()) {
            String filmsPerYearEnumeration = wikiComicFilmScanner.next();
            Matcher matcherEnum = comicEnum.matcher(filmsPerYearEnumeration);
            while (matcherEnum.find()) {
                String comicTitle = matcherEnum.group(0);
                String filmTitle = matcherEnum.group(2);
                System.out.println("---------------------------------");
                System.out.println(comicTitle);
                System.out.println(filmTitle);
            }
        }
        return comicMap;
    }

}

在操作上方显示 PrintWithDetail 作为名称。

但是,我需要将 PrintWithDetail 更改为荷兰语。

1 个答案:

答案 0 :(得分:2)

覆盖公共财产$name

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

所以在您的示例中

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']));
    }
}

您可以在操作nova/src/Actions/Action.php扩展的类中看到所有可以更改的内容

希望这会有所帮助