diff --git a/.env.example b/.env.example index 8cb54a6c..164fbdd9 100644 --- a/.env.example +++ b/.env.example @@ -5,9 +5,20 @@ APP_DEBUG=false APP_URL=http://localhost #list with timezones https://www.php.net/manual/en/timezones.php APP_TIMEZONE=UTC + +# If set to true, Language is chosen automatically depending on the users browserlanguage. +DYNAMIC_LOCALE = false + +# The language of the Dashboard. This is also the fallback if dynamic_locale is true but no translation is found LOCALE=en + +# You can grab the Language-Codes for the Datatables from this Website https://datatables.net/plug-ins/i18n/ DATATABLE_LOCALE=en-gb +#The languages you DO NOT want to support on your Controlpanel split by comma. +#Remove the language to make it available +UNSUPPORTED_LOCALES=german,italian,chinese + DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 diff --git a/app/Http/Controllers/TranslationController.php b/app/Http/Controllers/TranslationController.php new file mode 100644 index 00000000..40a6bd05 --- /dev/null +++ b/app/Http/Controllers/TranslationController.php @@ -0,0 +1,21 @@ +inputLocale); + return redirect()->back(); + } +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 6454849a..9b2e1fcd 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -4,7 +4,7 @@ namespace App\Http; use App\Http\Middleware\ApiAuthToken; use App\Http\Middleware\CheckSuspended; -use App\Http\Middleware\CreditsDisplayName; +use App\Http\Middleware\GlobalNames; use App\Http\Middleware\isAdmin; use App\Http\Middleware\LastSeen; use Illuminate\Foundation\Http\Kernel as HttpKernel; @@ -43,13 +43,14 @@ class Kernel extends HttpKernel \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, LastSeen::class, - CreditsDisplayName::class, + GlobalNames::class, + \App\Http\Middleware\SetLocale::class, ], 'api' => [ 'throttle:api', \Illuminate\Routing\Middleware\SubstituteBindings::class, - CreditsDisplayName::class + GlobalNames::class ], ]; diff --git a/app/Http/Middleware/CreditsDisplayName.php b/app/Http/Middleware/GlobalNames.php similarity index 64% rename from app/Http/Middleware/CreditsDisplayName.php rename to app/Http/Middleware/GlobalNames.php index a6962f41..519b111d 100644 --- a/app/Http/Middleware/CreditsDisplayName.php +++ b/app/Http/Middleware/GlobalNames.php @@ -6,7 +6,7 @@ use App\Models\Configuration; use Closure; use Illuminate\Http\Request; -class CreditsDisplayName +class GlobalNames { /** * Handle an incoming request. @@ -18,6 +18,11 @@ class CreditsDisplayName public function handle(Request $request, Closure $next) { define('CREDITS_DISPLAY_NAME' , Configuration::getValueByKey('CREDITS_DISPLAY_NAME' , 'Credits')); + + $unsupported_lang_array = explode(',', config("app.unsupported_locales")); + $unsupported_lang_array = array_map( 'strtolower', $unsupported_lang_array ); + define('UNSUPPORTED_LANGS', $unsupported_lang_array); + return $next($request); } } diff --git a/app/Http/Middleware/SetLocale.php b/app/Http/Middleware/SetLocale.php new file mode 100644 index 00000000..c87e891d --- /dev/null +++ b/app/Http/Middleware/SetLocale.php @@ -0,0 +1,231 @@ + "Afar", + "ab" => "Abkhazian", + "ae" => "Avestan", + "af" => "Afrikaans", + "ak" => "Akan", + "am" => "Amharic", + "an" => "Aragonese", + "ar" => "Arabic", + "as" => "Assamese", + "av" => "Avaric", + "ay" => "Aymara", + "az" => "Azerbaijani", + "ba" => "Bashkir", + "be" => "Belarusian", + "bg" => "Bulgarian", + "bh" => "Bihari", + "bi" => "Bislama", + "bm" => "Bambara", + "bn" => "Bengali", + "bo" => "Tibetan", + "br" => "Breton", + "bs" => "Bosnian", + "ca" => "Catalan", + "ce" => "Chechen", + "ch" => "Chamorro", + "co" => "Corsican", + "cr" => "Cree", + "cs" => "Czech", + "cu" => "Church Slavic", + "cv" => "Chuvash", + "cy" => "Welsh", + "da" => "Danish", + "de" => "German", + "dv" => "Divehi", + "dz" => "Dzongkha", + "ee" => "Ewe", + "el" => "Greek", + "en" => "English", + "eo" => "Esperanto", + "es" => "Spanish", + "et" => "Estonian", + "eu" => "Basque", + "fa" => "Persian", + "ff" => "Fulah", + "fi" => "Finnish", + "fj" => "Fijian", + "fo" => "Faroese", + "fr" => "French", + "fy" => "Western Frisian", + "ga" => "Irish", + "gd" => "Scottish Gaelic", + "gl" => "Galician", + "gn" => "Guarani", + "gu" => "Gujarati", + "gv" => "Manx", + "ha" => "Hausa", + "he" => "Hebrew", + "hi" => "Hindi", + "ho" => "Hiri Motu", + "hr" => "Croatian", + "ht" => "Haitian", + "hu" => "Hungarian", + "hy" => "Armenian", + "hz" => "Herero", + "ia" => "Interlingua (International Auxiliary Language Association)", + "id" => "Indonesian", + "ie" => "Interlingue", + "ig" => "Igbo", + "ii" => "Sichuan Yi", + "ik" => "Inupiaq", + "io" => "Ido", + "is" => "Icelandic", + "it" => "Italian", + "iu" => "Inuktitut", + "ja" => "Japanese", + "jv" => "Javanese", + "ka" => "Georgian", + "kg" => "Kongo", + "ki" => "Kikuyu", + "kj" => "Kwanyama", + "kk" => "Kazakh", + "kl" => "Kalaallisut", + "km" => "Khmer", + "kn" => "Kannada", + "ko" => "Korean", + "kr" => "Kanuri", + "ks" => "Kashmiri", + "ku" => "Kurdish", + "kv" => "Komi", + "kw" => "Cornish", + "ky" => "Kirghiz", + "la" => "Latin", + "lb" => "Luxembourgish", + "lg" => "Ganda", + "li" => "Limburgish", + "ln" => "Lingala", + "lo" => "Lao", + "lt" => "Lithuanian", + "lu" => "Luba-Katanga", + "lv" => "Latvian", + "mg" => "Malagasy", + "mh" => "Marshallese", + "mi" => "Maori", + "mk" => "Macedonian", + "ml" => "Malayalam", + "mn" => "Mongolian", + "mr" => "Marathi", + "ms" => "Malay", + "mt" => "Maltese", + "my" => "Burmese", + "na" => "Nauru", + "nb" => "Norwegian Bokmal", + "nd" => "North Ndebele", + "ne" => "Nepali", + "ng" => "Ndonga", + "nl" => "Dutch", + "nn" => "Norwegian Nynorsk", + "no" => "Norwegian", + "nr" => "South Ndebele", + "nv" => "Navajo", + "ny" => "Chichewa", + "oc" => "Occitan", + "oj" => "Ojibwa", + "om" => "Oromo", + "or" => "Oriya", + "os" => "Ossetian", + "pa" => "Panjabi", + "pi" => "Pali", + "pl" => "Polish", + "ps" => "Pashto", + "pt" => "Portuguese", + "qu" => "Quechua", + "rm" => "Raeto-Romance", + "rn" => "Kirundi", + "ro" => "Romanian", + "ru" => "Russian", + "rw" => "Kinyarwanda", + "sa" => "Sanskrit", + "sc" => "Sardinian", + "sd" => "Sindhi", + "se" => "Northern Sami", + "sg" => "Sango", + "si" => "Sinhala", + "sk" => "Slovak", + "sl" => "Slovenian", + "sm" => "Samoan", + "so" => "Somali", + "sq" => "Albanian", + "sr" => "Serbian", + "ss" => "Swati", + "st" => "Southern Sotho", + "su" => "Sundanese", + "sv" => "Swedish", + "sw" => "Swahili", + "ta" => "Tamil", + "te" => "Telugu", + "tg" => "Tajik", + "th" => "Thai", + "ti" => "Tigrinya", + "tk" => "Turkmen", + "tl" => "Tagalog", + "tn" => "Tswana", + "to" => "Tonga", + "tr" => "Turkish", + "ts" => "Tsonga", + "tt" => "Tatar", + "tw" => "Twi", + "ty" => "Tahitian", + "ug" => "Uighur", + "uk" => "Ukrainian", + "ur" => "Urdu", + "uz" => "Uzbek", + "ve" => "Venda", + "vi" => "Vietnamese", + "vo" => "Volapuk", + "wa" => "Walloon", + "wo" => "Wolof", + "xh" => "Xhosa", + "yi" => "Yiddish", + "yo" => "Yoruba", + "za" => "Zhuang", + "zh" => "Chinese", + "zu" => "Zulu" + ); + return array_search($name, array_flip($languageCodes)); + } + + /** + * + * Handle an incoming request. + * + * @param Request $request + * @param Closure $next + * @return mixed + */ + public function handle($request, Closure $next) + { + + if (Session::has('locale')) { + $locale = Session::get('locale', config('app.locale')); + } else { + if (!config('app.dynamic_locale')) { + $locale = config('app.locale'); + }else{ + $locale = substr($request->server('HTTP_ACCEPT_LANGUAGE'), 0, 2); + + if (!in_array($locale, config('app.available_locales')) + || in_array(strtolower($this->getLocaleCodeForDisplayLanguage($locale)), UNSUPPORTED_LANGS)) { + $locale = config('app.locale'); + } + + } + } + App::setLocale($locale); + + return $next($request); + } +} diff --git a/config/app.php b/config/app.php index 75201148..056d7ffe 100644 --- a/config/app.php +++ b/config/app.php @@ -70,6 +70,17 @@ return [ 'timezone' => env('APP_TIMEZONE', 'UTC'), + /* + |-------------------------------------------------------------------------- + | Dyamic Locales + |-------------------------------------------------------------------------- + | + | Change the Locale depending on the Users Browserlanguage + | Can either be true or false + | + */ + 'dynamic_locale' => env('DYNAMIC_LOCALE', false), + /* |-------------------------------------------------------------------------- | Application Locale Configuration @@ -84,6 +95,31 @@ return [ 'locale' => env('LOCALE', 'en'), + /* + |-------------------------------------------------------------------------- + | Available Locales + |-------------------------------------------------------------------------- + | + | You should not change this + | If the dashboard is 100% translated in a certain language, it will be added here + | + */ + 'available_locales' => array('English'=>'en','German'=>'de','Italian'=>'it','Chinese'=>'zh'), + + + /* + |-------------------------------------------------------------------------- + | Unsupported Locales + |-------------------------------------------------------------------------- + | + | Locales the Owner of the Dashboard does not want to support + | + | + */ + + 'unsupported_locales' => env("UNSUPPORTED_LOCALES", ""), + + /* |-------------------------------------------------------------------------- | Datatable Language Setting diff --git a/resources/views/layouts/main.blade.php b/resources/views/layouts/main.blade.php index 46019818..453258e6 100644 --- a/resources/views/layouts/main.blade.php +++ b/resources/views/layouts/main.blade.php @@ -41,11 +41,37 @@
Nodes
--}} -{{-- --}} -{{--Nodes
--}} + {{-- --}} + {{--Nests
--}} -{{-- --}} -{{--Nests
--}} + {{-- --}} + {{--