From 8fc30fbe3a7ba7cba081f2af82bbe8b81f089469 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Thu, 2 Feb 2017 15:05:33 +0100 Subject: [PATCH 1/5] 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 From d9225e65dfe26226965829d689442b352fbb253c Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Thu, 2 Feb 2017 15:30:40 +0100 Subject: [PATCH 2/5] move phraseapp js into own file --- public/js/phraseapp.js | 8 ++++++++ resources/themes/pterodactyl/layouts/auth.blade.php | 13 +------------ .../themes/pterodactyl/layouts/master.blade.php | 13 +------------ 3 files changed, 10 insertions(+), 24 deletions(-) create mode 100644 public/js/phraseapp.js diff --git a/public/js/phraseapp.js b/public/js/phraseapp.js new file mode 100644 index 000000000..a11a22655 --- /dev/null +++ b/public/js/phraseapp.js @@ -0,0 +1,8 @@ +window.PHRASEAPP_CONFIG = { + projectId: '94f8b39450cd749ae9c3cc0ab8cdb61d' +}; +(function() { + var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true; + phraseapp.src = ['https://', 'phraseapp.com/assets/in-context-editor/2.0/app.js?', new Date().getTime()].join(''); + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s); +})(); diff --git a/resources/themes/pterodactyl/layouts/auth.blade.php b/resources/themes/pterodactyl/layouts/auth.blade.php index 2163c9cc5..a6fbf86f5 100644 --- a/resources/themes/pterodactyl/layouts/auth.blade.php +++ b/resources/themes/pterodactyl/layouts/auth.blade.php @@ -50,17 +50,6 @@ {!! Theme::js('js/vendor/jquery/jquery.min.js') !!} {!! Theme::js('vendor/bootstrap/bootstrap.min.js') !!} - @if(config('app.phrase_in_context')) - - @endif + @if(config('app.phrase_in_context')) {!! Theme::js('js/phraseapp.js') !!} @endif diff --git a/resources/themes/pterodactyl/layouts/master.blade.php b/resources/themes/pterodactyl/layouts/master.blade.php index 250eb894d..57c7383e0 100644 --- a/resources/themes/pterodactyl/layouts/master.blade.php +++ b/resources/themes/pterodactyl/layouts/master.blade.php @@ -282,18 +282,7 @@ {!! 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 + @if(config('app.phrase_in_context')) {!! Theme::js('js/phraseapp.js') !!} @endif @show From 7f0608d412ae6e601154f5e7bbba62a062bfd393 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Thu, 2 Feb 2017 23:14:53 +0100 Subject: [PATCH 3/5] better naming of PhraseApp related stuff --- .../{Translator.php => PhraseAppTranslator.php} | 2 +- ...onProvider.php => PhraseAppTranslationProvider.php} | 10 +++++----- config/app.php | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) rename app/Extensions/{Translator.php => PhraseAppTranslator.php} (97%) rename app/Providers/{TranslationProvider.php => PhraseAppTranslationProvider.php} (86%) diff --git a/app/Extensions/Translator.php b/app/Extensions/PhraseAppTranslator.php similarity index 97% rename from app/Extensions/Translator.php rename to app/Extensions/PhraseAppTranslator.php index 5a3edcf4f..0d755664d 100644 --- a/app/Extensions/Translator.php +++ b/app/Extensions/PhraseAppTranslator.php @@ -26,7 +26,7 @@ namespace Pterodactyl\Extensions; use Illuminate\Translation\Translator as LaravelTranslator; -class Translator extends LaravelTranslator +class PhraseAppTranslator extends LaravelTranslator { /** * Get the translation for the given key. diff --git a/app/Providers/TranslationProvider.php b/app/Providers/PhraseAppTranslationProvider.php similarity index 86% rename from app/Providers/TranslationProvider.php rename to app/Providers/PhraseAppTranslationProvider.php index 474737b50..76de046ec 100644 --- a/app/Providers/TranslationProvider.php +++ b/app/Providers/PhraseAppTranslationProvider.php @@ -24,11 +24,11 @@ namespace Pterodactyl\Providers; -use Pterodactyl\Extensions\Translator as PterodactylTranslator; -use Illuminate\Translation\Translator; +use Pterodactyl\Extensions\PhraseAppTranslator; use Illuminate\Translation\TranslationServiceProvider; +use Illuminate\Translation\Translator as IlluminateTranslator; -class TranslationProvider extends TranslationServiceProvider { +class PhraseAppTranslationProvider extends TranslationServiceProvider { /** * Register the service provider. @@ -48,9 +48,9 @@ class TranslationProvider extends TranslationServiceProvider { $locale = $app['config']['app.locale']; if ($app['config']['app.phrase_in_context']) { - $trans = new PterodactylTranslator($loader, $locale); + $trans = new PhraseAppTranslator($loader, $locale); } else { - $trans = new Translator($loader, $locale); + $trans = new IlluminateTranslator($loader, $locale); } $trans->setFallback($app['config']['app.fallback_locale']); diff --git a/config/app.php b/config/app.php index abaabe25b..79bd1c07b 100644 --- a/config/app.php +++ b/config/app.php @@ -151,7 +151,7 @@ return [ Pterodactyl\Providers\AuthServiceProvider::class, Pterodactyl\Providers\EventServiceProvider::class, Pterodactyl\Providers\RouteServiceProvider::class, - Pterodactyl\Providers\TranslationProvider::class, + Pterodactyl\Providers\PhraseAppTranslationProvider::class, /* * Additional Dependencies From 7f1000dd8ac80e04ae221de3fdff52ed12a31cfd Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Fri, 3 Feb 2017 00:08:10 +0100 Subject: [PATCH 4/5] make dane and styleci happy --- app/Extensions/PhraseAppTranslator.php | 1 + app/Providers/PhraseAppTranslationProvider.php | 6 ++---- config/app.php | 1 - 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Extensions/PhraseAppTranslator.php b/app/Extensions/PhraseAppTranslator.php index 0d755664d..5a8d4a84e 100644 --- a/app/Extensions/PhraseAppTranslator.php +++ b/app/Extensions/PhraseAppTranslator.php @@ -40,6 +40,7 @@ class PhraseAppTranslator extends LaravelTranslator public function get($key, array $replace = [], $locale = null, $fallback = true) { $key = substr($key, strpos($key, '.') + 1); + return "{{__phrase_${key}__}}"; } } diff --git a/app/Providers/PhraseAppTranslationProvider.php b/app/Providers/PhraseAppTranslationProvider.php index 76de046ec..e6ba42116 100644 --- a/app/Providers/PhraseAppTranslationProvider.php +++ b/app/Providers/PhraseAppTranslationProvider.php @@ -28,8 +28,8 @@ use Pterodactyl\Extensions\PhraseAppTranslator; use Illuminate\Translation\TranslationServiceProvider; use Illuminate\Translation\Translator as IlluminateTranslator; -class PhraseAppTranslationProvider extends TranslationServiceProvider { - +class PhraseAppTranslationProvider extends TranslationServiceProvider +{ /** * Register the service provider. * @@ -58,6 +58,4 @@ class PhraseAppTranslationProvider extends TranslationServiceProvider { return $trans; }); } - - } diff --git a/config/app.php b/config/app.php index 79bd1c07b..58a095c40 100644 --- a/config/app.php +++ b/config/app.php @@ -139,7 +139,6 @@ return [ Illuminate\Redis\RedisServiceProvider::class, Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, Illuminate\Session\SessionServiceProvider::class, - //Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, Illuminate\Notifications\NotificationServiceProvider::class, From 600cc756370b22e989aba3f39a7f16f7be633b39 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Fri, 3 Feb 2017 00:29:50 +0100 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f2ee47a5c..78c3f20d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * Users can now have a username as well as client name assigned to their account. * Ability to create a node through the CLI using `pterodactyl:node` as well as locations via `pterodactyl:location`. * New theme (AdminLTE) for front-end with tweaks to backend files to work properly with it. +* Add support for PhraseApp's in-context editor ### Fixed * Bug causing error logs to be spammed if someone timed out on an ajax based page.