From 8fc30fbe3a7ba7cba081f2af82bbe8b81f089469 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Thu, 2 Feb 2017 15:05:33 +0100 Subject: [PATCH] add phraseapp in context editor --- app/Extensions/Translator.php | 45 +++++++++++++ app/Providers/TranslationProvider.php | 63 +++++++++++++++++++ config/app.php | 5 +- .../themes/pterodactyl/layouts/auth.blade.php | 13 ++++ .../pterodactyl/layouts/master.blade.php | 13 ++++ 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 app/Extensions/Translator.php create mode 100644 app/Providers/TranslationProvider.php diff --git a/app/Extensions/Translator.php b/app/Extensions/Translator.php new file mode 100644 index 000000000..5a3edcf4f --- /dev/null +++ b/app/Extensions/Translator.php @@ -0,0 +1,45 @@ +. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +namespace Pterodactyl\Extensions; + +use Illuminate\Translation\Translator as LaravelTranslator; + +class Translator extends LaravelTranslator +{ + /** + * Get the translation for the given key. + * + * @param string $key + * @param array $replace + * @param string|null $locale + * @param bool $fallback + * @return string|array|null + */ + public function get($key, array $replace = [], $locale = null, $fallback = true) + { + $key = substr($key, strpos($key, '.') + 1); + return "{{__phrase_${key}__}}"; + } +} diff --git a/app/Providers/TranslationProvider.php b/app/Providers/TranslationProvider.php new file mode 100644 index 000000000..474737b50 --- /dev/null +++ b/app/Providers/TranslationProvider.php @@ -0,0 +1,63 @@ +. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +namespace Pterodactyl\Providers; + +use Pterodactyl\Extensions\Translator as PterodactylTranslator; +use Illuminate\Translation\Translator; +use Illuminate\Translation\TranslationServiceProvider; + +class TranslationProvider extends TranslationServiceProvider { + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + $this->registerLoader(); + + $this->app->singleton('translator', function ($app) { + $loader = $app['translation.loader']; + + // When registering the translator component, we'll need to set the default + // locale as well as the fallback locale. So, we'll grab the application + // configuration so we can easily get both of these values from there. + $locale = $app['config']['app.locale']; + + if ($app['config']['app.phrase_in_context']) { + $trans = new PterodactylTranslator($loader, $locale); + } else { + $trans = new Translator($loader, $locale); + } + + $trans->setFallback($app['config']['app.fallback_locale']); + + return $trans; + }); + } + + +} diff --git a/config/app.php b/config/app.php index bb517f5f7..abaabe25b 100644 --- a/config/app.php +++ b/config/app.php @@ -6,6 +6,8 @@ return [ 'version' => env('APP_VERSION', 'canary'), + 'phrase_in_context' => env('PHRASE_IN_CONTEXT', false), + /* |-------------------------------------------------------------------------- | Application Debug Mode @@ -137,7 +139,7 @@ return [ Illuminate\Redis\RedisServiceProvider::class, Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, Illuminate\Session\SessionServiceProvider::class, - Illuminate\Translation\TranslationServiceProvider::class, + //Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, Illuminate\Notifications\NotificationServiceProvider::class, @@ -149,6 +151,7 @@ return [ Pterodactyl\Providers\AuthServiceProvider::class, Pterodactyl\Providers\EventServiceProvider::class, Pterodactyl\Providers\RouteServiceProvider::class, + Pterodactyl\Providers\TranslationProvider::class, /* * Additional Dependencies diff --git a/resources/themes/pterodactyl/layouts/auth.blade.php b/resources/themes/pterodactyl/layouts/auth.blade.php index 58758f4fa..2163c9cc5 100644 --- a/resources/themes/pterodactyl/layouts/auth.blade.php +++ b/resources/themes/pterodactyl/layouts/auth.blade.php @@ -49,5 +49,18 @@ {!! Theme::js('js/vendor/jquery/jquery.min.js') !!} {!! Theme::js('vendor/bootstrap/bootstrap.min.js') !!} + + @if(config('app.phrase_in_context')) + + @endif diff --git a/resources/themes/pterodactyl/layouts/master.blade.php b/resources/themes/pterodactyl/layouts/master.blade.php index 19b03380f..250eb894d 100644 --- a/resources/themes/pterodactyl/layouts/master.blade.php +++ b/resources/themes/pterodactyl/layouts/master.blade.php @@ -281,6 +281,19 @@ {!! Theme::js('vendor/adminlte/app.min.js') !!} {!! Theme::js('js/vendor/socketio/socket.io.min.js') !!} {!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js') !!} + + @if(config('app.phrase_in_context')) + + @endif @show