-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc7ac0d
commit 01a815f
Showing
7 changed files
with
128 additions
and
0 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
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,10 @@ | ||
<?php | ||
|
||
return [ | ||
'language' => [ | ||
'url' => 'rocket/language', | ||
'routename' => 'rocket.language.save', | ||
'middleware' => [] | ||
] | ||
|
||
]; |
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,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; | ||
} | ||
} |
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,4 @@ | ||
<?php | ||
Route::post(config('rocketframework.language.url'),'IanRothmann\RocketLaravelAppFramework\Language\RocketLanguage@save') | ||
->middleware(config('rocketframework.language.middleware')) | ||
->name(config('rocketframework.language.routename')); |
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,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); | ||
} | ||
|
||
} |