z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.13k stars 2.81k forks source link

Translate select2 not working #5753

Closed gomes2191 closed 1 year ago

gomes2191 commented 1 year ago

Description:

Does anyone know how to solve the select2 plugin not translating problem? I've tried setting in Select.php and it didn't work. image

Ladel commented 1 year ago

Check out this option, bad code but quick solution

diff --git a/laravel-admin/src/Form/Field/Select.php b/laravel-admin/src/Form/Field/Select.php
index c3a88f9..6f7bef7 100644
--- a/laravel-admin/src/Form/Field/Select.php
+++ b/laravel-admin/src/Form/Field/Select.php
@@ -25,6 +25,7 @@ class Select extends Field
      */
     protected static $js = [
         '/vendor/laravel-admin/AdminLTE/plugins/select2/select2.full.min.js',
+        '/vendor/laravel-admin/AdminLTE/plugins/select2/i18n/pt-BR.js',
     ];

     /**
@@ -40,7 +41,7 @@ class Select extends Field
     /**
      * @var array
      */
-    protected $config = [];
+    protected $config = ['language' => 'pt-BR'];

     /**
      * @var string

Dynamic change

$form->select($column[, $label])
          ->options([1 => 'foo', 2 => 'bar', 'val' => 'Option name'])
          ->config('language', config('app.locale'));
gomes2191 commented 1 year ago

Solved, thanks @Ladel for the tip.