-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Web Interface was added and some minor changes.
- Loading branch information
Showing
13 changed files
with
403 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "0.1.x-dev" | ||
"dev-master": "0.2.x-dev" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,24 @@ | ||
<?php | ||
|
||
return [ | ||
/** | ||
* To save some time interacting with the database, you can turn | ||
* the storing of the viewed_at field off. | ||
*/ | ||
'update_viewed_at' => true, | ||
|
||
/** | ||
* This is the prefix for on which URI the Translations Manager will | ||
* be available. You can leave it just as is in most cases. | ||
*/ | ||
'route_prefix' => '_translations', | ||
|
||
/** | ||
* If your using the Laravel Debugbar provided by Barryvdh\Debugbar | ||
* you might want to disable this in the Translations Manager. | ||
* This interface can generate a bunch of Ajax calls that will slow | ||
* the translation process down. | ||
* You can however turn it on, the choice is yours. | ||
*/ | ||
'disable_debugbar' => true, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
return [ | ||
'title' => 'Translations Manager', | ||
'help' => 'Select your preferred group and locale below and start translating.', | ||
'locale_placeholder' => 'Enter the locale you wish to edit. (example: en)', | ||
'button' => 'Load', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
return [ | ||
'title' => 'Vertalingen beheer', | ||
'help' => 'Selecteer de groep en de taal van uw voorkeur en start met vertalen.', | ||
'locale_placeholder' => 'Geef de taal op die uw wilt bewerken. (bijvoorbeeld: nl)', | ||
'button' => 'Inladen', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php namespace Hpolthof\Translation\Controllers; | ||
|
||
use Hpolthof\Translation\TranslationException; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Routing\Controller; | ||
|
||
class TranslationsController extends Controller { | ||
|
||
public function __construct() { | ||
// Disable the Laravel Debugbar | ||
$app = app(); | ||
if($app->offsetExists('debugbar') && $app['config']->get('translation-db.disable_debugbar')) { | ||
$app['debugbar']->disable(); | ||
} | ||
} | ||
|
||
public function getIndex() { | ||
return view('translation::index'); | ||
} | ||
|
||
public function getGroups() { | ||
return \DB::table('translations') | ||
->select('group') | ||
->distinct() | ||
->orderBy('group') | ||
->lists('group'); | ||
} | ||
|
||
public function getLocales() { | ||
return \DB::table('translations') | ||
->select('locale') | ||
->distinct() | ||
->orderBy('locale') | ||
->lists('locale'); | ||
} | ||
|
||
public function postItems(Request $request) { | ||
if(strlen($request->get('translate')) == 0) throw new TranslationException(); | ||
|
||
$base = \DB::table('translations') | ||
->select('name', 'value') | ||
->where('locale', $request->get('locale')) | ||
->where('group', $request->get('group')) | ||
->orderBy('name') | ||
->get(); | ||
$new = \DB::table('translations') | ||
->select('name', 'value') | ||
->where('locale', strtolower($request->get('translate'))) | ||
->where('group', $request->get('group')) | ||
->orderBy('name') | ||
->lists('value', 'name'); | ||
|
||
foreach($base as &$item) { | ||
$translate = null; | ||
|
||
if(array_key_exists($item->name, $new)) { | ||
$translate = $new[$item->name]; | ||
} | ||
$item->translation = $translate; | ||
} | ||
|
||
return $base; | ||
} | ||
|
||
public function postStore(Request $request) { | ||
$item = \DB::table('translations') | ||
->where('locale', strtolower($request->get('locale'))) | ||
->where('group', $request->get('group')) | ||
->where('name', $request->get('name'))->first(); | ||
|
||
$data = [ | ||
'locale' => strtolower($request->get('locale')), | ||
'group' => $request->get('group'), | ||
'name' => $request->get('name'), | ||
'value' => $request->get('value'), | ||
'updated_at' => date_create(), | ||
]; | ||
|
||
if($item === null) { | ||
$data = array_merge($data, [ | ||
'created_at' => date_create(), | ||
]); | ||
$result = \DB::table('translations')->insert($data); | ||
} else { | ||
$result = \DB::table('translations')->where('id', $item->id)->update($data); | ||
} | ||
|
||
if(!$result) { | ||
throw new TranslationException('Database error...'); | ||
} | ||
return 'OK'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php namespace Hpolthof\Translation\DataCollector; | ||
|
||
use DebugBar\DataCollector\DataCollector; | ||
use Symfony\Component\HttpKernel\DataCollector\Util\ValueExporter; | ||
|
||
class TranslationCollector extends DataCollector | ||
{ | ||
protected $items = array(); | ||
protected $collect_data; | ||
/** | ||
* Create a ViewCollector | ||
* | ||
* @param bool $collectData Collects view data when tru | ||
*/ | ||
public function __construct($collectData = true) | ||
{ | ||
$this->collect_data = $collectData; | ||
$this->name = 'translation'; | ||
$this->items = array(); | ||
$this->exporter = new ValueExporter(); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'translation'; | ||
} | ||
|
||
public function getWidgets() | ||
{ | ||
return array( | ||
'views' => array( | ||
'icon' => 'leaf', | ||
'widget' => 'PhpDebugBar.Widgets.TemplatesWidget', | ||
'map' => 'translation', | ||
'default' => '[]' | ||
), | ||
'views:badge' => array( | ||
'map' => 'translation.count', | ||
'default' => 0 | ||
) | ||
); | ||
} | ||
|
||
public function addTranslation($translation) | ||
{ | ||
$this->items[] = $translation; | ||
} | ||
|
||
public function collect() | ||
{ | ||
$items = $this->items; | ||
return array( | ||
'count' => count($items), | ||
'translation' => $items, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Bootstrap 101 Template</title> | ||
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> | ||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> | ||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script> | ||
|
||
@include('translation::javascript') | ||
@include('translation::style') | ||
</head> | ||
<body> | ||
|
||
<div class="container-fluid" ng-app="trans" ng-controller="Translations"> | ||
|
||
<h1>{{ trans('translation::manager.title') }}</h1> | ||
<p> | ||
{{ trans('translation::manager.help') }} | ||
</p> | ||
|
||
<div ng-if="message" class="alert alert-[[ message.type ]]" role="alert"> | ||
[[ message.text ]] | ||
</div> | ||
|
||
<div class="row" style="margin-bottom:10px"> | ||
|
||
<div class="col-md-3"> | ||
<select ng-model="currentGroup" ng-change="clear()" class="form-control"> | ||
<option ng-repeat="group in groups">[[ group ]]</option> | ||
</select> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<select ng-model="currentLocale" ng-change="clear()" class="form-control"> | ||
<option ng-repeat="locale in locales">[[ locale ]]</option> | ||
</select> | ||
</div> | ||
|
||
<div class="col-md-4"> | ||
<input ng-change="clear()" class="form-control" maxlength="2" type="text" ng-model="currentEditable" placeholder="{{ trans('translation::manager.locale_placeholder') }}" /> | ||
</div> | ||
|
||
<div class="col-md-1"> | ||
<button class="btn btn-primary form-control" ng-click="fetch()"> | ||
{{ trans('translation::manager.button') }} | ||
</button> | ||
</div> | ||
</div> | ||
|
||
<div class="row datarow" ng-repeat="item in items"> | ||
<div class="col-md-3 text"> | ||
[[ item.name ]] | ||
</div> | ||
<div class="col-md-4 text"> | ||
[[ item.value ]] | ||
</div> | ||
<div class="col-md-5"> | ||
<textarea class="form-control" ng-blur="store($index)" ng-model="item.translation" onfocus="jQuery(this).closest('.row').addClass('bg-success');" onblur="jQuery(this).closest('.row').removeClass('bg-success');"></textarea> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.