Browse Source

修复 - dcat admin 语言包bug

notfff 7 months ago
parent
commit
6365b4dcac
1 changed files with 16 additions and 0 deletions
  1. 16 0
      vendor/dcat/laravel-admin/src/AdminServiceProvider.php

+ 16 - 0
vendor/dcat/laravel-admin/src/AdminServiceProvider.php

@@ -107,6 +107,7 @@ class AdminServiceProvider extends ServiceProvider
     {
         $this->registerDefaultSections();
         $this->registerViews();
+        $this->registerTranslations();
         $this->ensureHttps();
         $this->bootApplication();
         $this->registerPublishing();
@@ -127,6 +128,21 @@ class AdminServiceProvider extends ServiceProvider
         $this->loadViewsFrom(__DIR__.'/../resources/views', 'admin');
     }
 
+     protected function registerTranslations()
+    {
+        // For Laravel 11 compatibility, we need to merge translations into the main lang directory
+        // instead of using a namespace, so that __('admin.key') works without admin:: prefix
+        $langPath = $this->app->langPath();
+        $adminLangPath = __DIR__.'/../resources/lang';
+
+        // Check if admin translations are already published
+        if (!file_exists($langPath.'/zh_CN/admin.php') && file_exists($adminLangPath)) {
+            // Load translations from vendor directory without namespace
+            $this->loadTranslationsFrom($adminLangPath);
+        }
+    }
+
+
     /**
      * 是否强制使用https.
      *