-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add in place edit of translations in the whole site
- Loading branch information
Showing
4 changed files
with
76 additions
and
24 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
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 |
---|---|---|
@@ -1,42 +1,84 @@ | ||
<?php namespace Barryvdh\TranslationManager; | ||
|
||
use Illuminate\Support\Facades\URL; | ||
use Illuminate\Translation\LoaderInterface; | ||
use Illuminate\Translation\Translator as LaravelTranslator; | ||
use Illuminate\Events\Dispatcher; | ||
|
||
class Translator extends LaravelTranslator { | ||
class Translator extends LaravelTranslator | ||
{ | ||
|
||
/** @var Dispatcher */ | ||
protected $events; | ||
|
||
/** | ||
* Translator constructor. | ||
*/ | ||
public | ||
function __construct(LoaderInterface $loader, $locale) | ||
{ | ||
parent::__construct($loader, $locale); | ||
} | ||
|
||
/** | ||
* Get the translation for the given key. | ||
* | ||
* @param string $key | ||
* @param array $replace | ||
* @param string $locale | ||
* @param string $key | ||
* @param array $replace | ||
* @param string $locale | ||
* | ||
* @return string | ||
*/ | ||
public function get($key, array $replace = array(), $locale = null) | ||
public | ||
function get($key, array $replace = array(), $locale = null) | ||
{ | ||
$thisLocale = $this->parseLocale($locale); | ||
|
||
if ($thisLocale[0] !== 'dbg' && $thisLocale[1] === 'dbg') | ||
{ | ||
list($namespace, $group, $item) = $this->parseKey($key); | ||
|
||
// TODO: add config to translation manager to define exclude groups for in page edit | ||
if ($this->manager && $namespace === '*' && $group && $group !== 'page-titles' && $item) | ||
{ | ||
$t = $this->manager->missingKey($namespace, $group, $item); | ||
if ($t) | ||
{ | ||
if (is_null($t->value)) $t->value = parent::get($key, $replace, $locale); | ||
|
||
$result = '<a href="#edit" class="editable status-' . ($t ? $t->status : 0) . ' locale-' . $t->locale . '" data-locale="' . $t->locale . '" | ||
data-name="' . $t->locale . '"|" . ' . $t->key . '" id="username" data-type="textarea" data-pk="' . ($t ? $t->id : 0) . '" | ||
data-url="' . URL::action('Barryvdh\TranslationManager\Controller@postEdit', array($t->group)) . '" | ||
data-inputclass="editable-input" | ||
data-title="' . parent::trans('laravel-translation-manager::translations.enter-translation') . ': [' . $t->locale . '] ' . $key . '">' | ||
. ($t ? htmlentities($t->value, ENT_QUOTES, 'UTF-8', false) : '') . '</a> '//. (!$t ? '' : ($t->saved_value === $t->value ? '' : ' [' . \Barryvdh\TranslationManager\Controller::mb_renderDiffHtml($t->saved_value, $t->value) . ']')); | ||
; | ||
return $result; | ||
} | ||
} | ||
} | ||
|
||
$result = parent::get($key, $replace, $locale); | ||
if($result === $key){ | ||
if ($result === $key) | ||
{ | ||
$this->notifyMissingKey($key); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function setTranslationManager(Manager $manager) | ||
public | ||
function setTranslationManager(Manager $manager) | ||
{ | ||
$this->manager = $manager; | ||
} | ||
|
||
protected function notifyMissingKey($key) | ||
protected | ||
function notifyMissingKey($key) | ||
{ | ||
list($namespace, $group, $item) = $this->parseKey($key); | ||
if($this->manager && $namespace === '*' && $group && $item ){ | ||
if ($this->manager && $namespace === '*' && $group && $item) | ||
{ | ||
$this->manager->missingKey($namespace, $group, $item); | ||
} | ||
} | ||
|
||
} |