From 6d505d275bf8704bbe2b252fc67f80238060a56a Mon Sep 17 00:00:00 2001 From: printempw Date: Tue, 7 Aug 2018 13:17:28 +0800 Subject: [PATCH] Fix Hook::registerPluginTransScripts method --- app/Services/Hook.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/Services/Hook.php b/app/Services/Hook.php index d398ca83..1b8ebf96 100644 --- a/app/Services/Hook.php +++ b/app/Services/Hook.php @@ -57,14 +57,25 @@ class Hook }); } - public static function registerPluginTransScripts($id, $pages = ['*'], $priority = 1) + public static function registerPluginTransScripts($id, $pages = ['*'], $priority = 999) { - $basepath = plugin($id)->getPath().'/'; - $relative = 'lang/'.config('app.locale').'/locale.js'; + Event::listen(Events\RenderingFooter::class, function ($event) use ($id, $pages) { + foreach ($pages as $pattern) { + if (! app('request')->is($pattern)) + continue; - if (file_exists($basepath.$relative)) { - static::addScriptFileToPage(plugin_assets($id, $relative), $pages, $priority); - } + // We will determine current locale in the event callback, + // otherwise the locale is not properly detected. + $basepath = plugin($id)->getPath().'/'; + $relative = 'lang/'.config('app.locale').'/locale.js'; + + if (file_exists($basepath.$relative)) { + $event->addContent(''); + } + + return; + } + }, $priority); } public static function addStyleFileToPage($urls, $pages = ['*'], $priority = 1)