Skip to content

Commit

Permalink
Language Edit
Browse files Browse the repository at this point in the history
  • Loading branch information
ianrothmann1 committed Sep 3, 2017
1 parent bc7ac0d commit 01a815f
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"require": {
"php": ">=5.4.0",
"laravel/framework": ">=5.4.0",
"spatie/laravel-translation-loader": "^2.0",
"ianrothmann/laravel-vue-bridge": "*"
},
"autoload": {
Expand Down
10 changes: 10 additions & 0 deletions src/Config/rocketframework.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'language' => [
'url' => 'rocket/language',
'routename' => 'rocket.language.save',
'middleware' => []
]

];
60 changes: 60 additions & 0 deletions src/Language/RocketLanguage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace IanRothmann\RocketLaravelAppFramework\Language;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Blade;

class RocketLanguage
{
protected $editMode=false;

public function __construct(){

}

public static function register(){
Blade::directive('editabletext', function ($languageLine) {
return "<?php echo getEditableTranslation($languageLine) ?>";
});

Blade::directive('editablehtml', function ($languageLine) {
return "<?php echo getEditableTranslation($languageLine,true) ?>";
});
}

public function isInEditMode(){
return $this->editMode;
}

public function activateEditMode(){
$this->editMode=true;
}

public function deactivateEditMode(){
$this->editMode=false;
}

public function save(Request $request){
$modelClass=config('translation-loader.model');
$line=explode('.',$request->get('line'));
$group=$line[0];
$key=$line[1];
$locale=$request->get('locale');
$content=$request->get('content');
$languageLine=$modelClass::where('group',$group)->where('key',$key)->first();
if($languageLine==null){
$modelClass::create([
'group' => $group,
'key' => $key,
'text' => [$locale => $content],
]);
}else{
$text=$languageLine->text;
$text[$locale]=$content;
$languageLine->text=$text;
$languageLine->save();
}
return $languageLine;
}
}
15 changes: 15 additions & 0 deletions src/RocketLaravelAppFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
namespace IanRothmann\RocketLaravelAppFramework;


use IanRothmann\RocketLaravelAppFramework\Language\RocketLanguage;
use VueBridge;

class RocketLaravelAppFramework
{
/** @var RocketMenu[] $menus
*/
public $menus=[];
public $language;

public function __construct(){
$self=$this;
VueBridge::exposeClosureResult('rocketMenus',function() use ($self){
return $self->getMenus();
});
$this->language=new RocketLanguage();
}

public function menu($id){
Expand All @@ -34,4 +37,16 @@ public function menu($id){
public function getMenus(){
return $this->menus;
}

public function activateLanguageEdit(){
$this->language->activateEditMode();
}

public function deactivateLanguageEdit(){
$this->language->deactivateEditMode();
}

public function isInLanguageEditMode(){
return $this->language->isInEditMode();
}
}
4 changes: 4 additions & 0 deletions src/Routes/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
Route::post(config('rocketframework.language.url'),'IanRothmann\RocketLaravelAppFramework\Language\RocketLanguage@save')
->middleware(config('rocketframework.language.middleware'))
->name(config('rocketframework.language.routename'));
27 changes: 27 additions & 0 deletions src/ServiceProviders/RocketAppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,40 @@
namespace IanRothmann\RocketLaravelAppFramework\ServiceProviders;


use Blade;
use IanRothmann\RocketLaravelAppFramework\Language\RocketLanguage;
use Illuminate\Support\ServiceProvider;

class RocketAppServiceProvider extends ServiceProvider
{

public function boot()
{
$this->loadRoutesFrom(__DIR__.'/../Routes/routes.php');
$this->publishes([
__DIR__.'/../Config/rocketframework.php' => config_path('rocketframework.php'),
],'config');
}

public function register(){
$this->app->bind('rocket-app','IanRothmann\RocketLaravelAppFramework\RocketLaravelAppFramework');
$this->registerHelpers();
RocketLanguage::register();

}


/**
* Register helpers file
*/
public function registerHelpers()
{
if (file_exists( __DIR__.DIRECTORY_SEPARATOR.'../helpers.php'))
{
require __DIR__.DIRECTORY_SEPARATOR.'../helpers.php';
}
}



}
11 changes: 11 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

function getEditableTranslation($languageLine,$html=false){

if(\IanRothmann\RocketLaravelAppFramework\Facades\Rocket::isInLanguageEditMode()){
return '<rocket-editinplace :html="'.($html?'true':'false').'" url="'.route('rocket.language.save').'" locale="'.App::getLocale().'" line="'.$languageLine.'">'.trans($languageLine).'</rocket-editinplace>';
}else{
return trans($languageLine);
}

}

0 comments on commit 01a815f

Please sign in to comment.