Skip to content

Commit 8cac2a3

Browse files
authored
Merge pull request pterodactyl#285 from Pterodactyl/feature/phrase-in-context
add phraseapp in context editor
2 parents fb589a7 + 600cc75 commit 8cac2a3

File tree

7 files changed

+123
-1
lines changed

7 files changed

+123
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1010
* Users can now have a username as well as client name assigned to their account.
1111
* Ability to create a node through the CLI using `pterodactyl:node` as well as locations via `pterodactyl:location`.
1212
* New theme (AdminLTE) for front-end with tweaks to backend files to work properly with it.
13+
* Add support for PhraseApp's in-context editor
1314

1415
### Fixed
1516
* Bug causing error logs to be spammed if someone timed out on an ajax based page.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Extensions;
26+
27+
use Illuminate\Translation\Translator as LaravelTranslator;
28+
29+
class PhraseAppTranslator extends LaravelTranslator
30+
{
31+
/**
32+
* Get the translation for the given key.
33+
*
34+
* @param string $key
35+
* @param array $replace
36+
* @param string|null $locale
37+
* @param bool $fallback
38+
* @return string|array|null
39+
*/
40+
public function get($key, array $replace = [], $locale = null, $fallback = true)
41+
{
42+
$key = substr($key, strpos($key, '.') + 1);
43+
44+
return "{{__phrase_${key}__}}";
45+
}
46+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Providers;
26+
27+
use Pterodactyl\Extensions\PhraseAppTranslator;
28+
use Illuminate\Translation\TranslationServiceProvider;
29+
use Illuminate\Translation\Translator as IlluminateTranslator;
30+
31+
class PhraseAppTranslationProvider extends TranslationServiceProvider
32+
{
33+
/**
34+
* Register the service provider.
35+
*
36+
* @return void
37+
*/
38+
public function register()
39+
{
40+
$this->registerLoader();
41+
42+
$this->app->singleton('translator', function ($app) {
43+
$loader = $app['translation.loader'];
44+
45+
// When registering the translator component, we'll need to set the default
46+
// locale as well as the fallback locale. So, we'll grab the application
47+
// configuration so we can easily get both of these values from there.
48+
$locale = $app['config']['app.locale'];
49+
50+
if ($app['config']['app.phrase_in_context']) {
51+
$trans = new PhraseAppTranslator($loader, $locale);
52+
} else {
53+
$trans = new IlluminateTranslator($loader, $locale);
54+
}
55+
56+
$trans->setFallback($app['config']['app.fallback_locale']);
57+
58+
return $trans;
59+
});
60+
}
61+
}

config/app.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
'version' => env('APP_VERSION', 'canary'),
88

9+
'phrase_in_context' => env('PHRASE_IN_CONTEXT', false),
10+
911
/*
1012
|--------------------------------------------------------------------------
1113
| Application Debug Mode
@@ -137,7 +139,6 @@
137139
Illuminate\Redis\RedisServiceProvider::class,
138140
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
139141
Illuminate\Session\SessionServiceProvider::class,
140-
Illuminate\Translation\TranslationServiceProvider::class,
141142
Illuminate\Validation\ValidationServiceProvider::class,
142143
Illuminate\View\ViewServiceProvider::class,
143144
Illuminate\Notifications\NotificationServiceProvider::class,
@@ -149,6 +150,7 @@
149150
Pterodactyl\Providers\AuthServiceProvider::class,
150151
Pterodactyl\Providers\EventServiceProvider::class,
151152
Pterodactyl\Providers\RouteServiceProvider::class,
153+
Pterodactyl\Providers\PhraseAppTranslationProvider::class,
152154

153155
/*
154156
* Additional Dependencies

public/js/phraseapp.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
window.PHRASEAPP_CONFIG = {
2+
projectId: '94f8b39450cd749ae9c3cc0ab8cdb61d'
3+
};
4+
(function() {
5+
var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true;
6+
phraseapp.src = ['https://', 'phraseapp.com/assets/in-context-editor/2.0/app.js?', new Date().getTime()].join('');
7+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s);
8+
})();

resources/themes/pterodactyl/layouts/auth.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,7 @@
4949
</div>
5050
{!! Theme::js('js/vendor/jquery/jquery.min.js') !!}
5151
{!! Theme::js('vendor/bootstrap/bootstrap.min.js') !!}
52+
53+
@if(config('app.phrase_in_context')) {!! Theme::js('js/phraseapp.js') !!} @endif
5254
</body>
5355
</html>

resources/themes/pterodactyl/layouts/master.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ class="active"
281281
{!! Theme::js('vendor/adminlte/app.min.js') !!}
282282
{!! Theme::js('js/vendor/socketio/socket.io.min.js') !!}
283283
{!! Theme::js('vendor/bootstrap-notify/bootstrap-notify.min.js') !!}
284+
285+
@if(config('app.phrase_in_context')) {!! Theme::js('js/phraseapp.js') !!} @endif
284286
@show
285287
</body>
286288
</html>

0 commit comments

Comments
 (0)