Skip to content

Commit 8fc30fb

Browse files
committed
add phraseapp in context editor
1 parent e5ed1c7 commit 8fc30fb

File tree

5 files changed

+138
-1
lines changed

5 files changed

+138
-1
lines changed

app/Extensions/Translator.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 Translator 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+
return "{{__phrase_${key}__}}";
44+
}
45+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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\Translator as PterodactylTranslator;
28+
use Illuminate\Translation\Translator;
29+
use Illuminate\Translation\TranslationServiceProvider;
30+
31+
class TranslationProvider 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 PterodactylTranslator($loader, $locale);
52+
} else {
53+
$trans = new Translator($loader, $locale);
54+
}
55+
56+
$trans->setFallback($app['config']['app.fallback_locale']);
57+
58+
return $trans;
59+
});
60+
}
61+
62+
63+
}

config/app.php

Lines changed: 4 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,7 @@
137139
Illuminate\Redis\RedisServiceProvider::class,
138140
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
139141
Illuminate\Session\SessionServiceProvider::class,
140-
Illuminate\Translation\TranslationServiceProvider::class,
142+
//Illuminate\Translation\TranslationServiceProvider::class,
141143
Illuminate\Validation\ValidationServiceProvider::class,
142144
Illuminate\View\ViewServiceProvider::class,
143145
Illuminate\Notifications\NotificationServiceProvider::class,
@@ -149,6 +151,7 @@
149151
Pterodactyl\Providers\AuthServiceProvider::class,
150152
Pterodactyl\Providers\EventServiceProvider::class,
151153
Pterodactyl\Providers\RouteServiceProvider::class,
154+
Pterodactyl\Providers\TranslationProvider::class,
152155

153156
/*
154157
* Additional Dependencies

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,18 @@
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'))
54+
<script>
55+
window.PHRASEAPP_CONFIG = {
56+
projectId: '94f8b39450cd749ae9c3cc0ab8cdb61d'
57+
};
58+
(function() {
59+
var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true;
60+
phraseapp.src = ['https://', 'phraseapp.com/assets/in-context-editor/2.0/app.js?', new Date().getTime()].join('');
61+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s);
62+
})();
63+
</script>
64+
@endif
5265
</body>
5366
</html>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,19 @@ 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'))
286+
<script>
287+
window.PHRASEAPP_CONFIG = {
288+
projectId: '94f8b39450cd749ae9c3cc0ab8cdb61d'
289+
};
290+
(function() {
291+
var phraseapp = document.createElement('script'); phraseapp.type = 'text/javascript'; phraseapp.async = true;
292+
phraseapp.src = ['https://', 'phraseapp.com/assets/in-context-editor/2.0/app.js?', new Date().getTime()].join('');
293+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(phraseapp, s);
294+
})();
295+
</script>
296+
@endif
284297
@show
285298
</body>
286299
</html>

0 commit comments

Comments
 (0)