diff --git a/src/Barryvdh/TranslationManager/Manager.php b/src/Barryvdh/TranslationManager/Manager.php index 5c74304..92edc08 100644 --- a/src/Barryvdh/TranslationManager/Manager.php +++ b/src/Barryvdh/TranslationManager/Manager.php @@ -26,20 +26,31 @@ function __construct(Application $app, Filesystem $files, Dispatcher $events) $this->app = $app; $this->files = $files; $this->events = $events; - $this->config = $app['config']['laravel-translation-manager::config']; + + // when instantiated from the service provider, config info is not yet loaded, trying to get it here + // causes a problem since none of the keys are defined. + $this->config = null; + } + + protected + function config() + { + return $this->config ?: $this->config = $this->app['config']['laravel-translation-manager::config']; } public function missingKey($namespace, $group, $key) { - if (!in_array($group, $this->config['exclude_groups'])) + if (!in_array($group, $this->config()['exclude_groups'])) { - Translation::firstOrCreate(array( + $translation = Translation::firstOrCreate(array( 'locale' => $this->app['config']['app.locale'], 'group' => $group, 'key' => $key, )); + return $translation; } + return null; } public @@ -56,7 +67,7 @@ function importTranslations($replace = false) $info = pathinfo($file); $group = $info['filename']; - if (in_array($group, $this->config['exclude_groups'])) + if (in_array($group, $this->config()['exclude_groups'])) { continue; } @@ -204,7 +215,7 @@ function formatForExport($trans, $indent = 0) public function exportTranslations($group) { - if (!in_array($group, $this->config['exclude_groups'])) + if (!in_array($group, $this->config()['exclude_groups'])) { if ($group == '*') $this->exportAllTranslations(); @@ -264,11 +275,11 @@ function getConfig($key = null) { if ($key == null) { - return $this->config; + return $this->config(); } else { - return $this->config[$key]; + return $this->config()[$key]; } } } diff --git a/src/Barryvdh/TranslationManager/ManagerServiceProvider.php b/src/Barryvdh/TranslationManager/ManagerServiceProvider.php index 157e7e2..282567b 100644 --- a/src/Barryvdh/TranslationManager/ManagerServiceProvider.php +++ b/src/Barryvdh/TranslationManager/ManagerServiceProvider.php @@ -9,7 +9,7 @@ class ManagerServiceProvider extends ServiceProvider { * * @var bool */ - protected $defer = false; + protected $defer = true; /** * Bootstrap the application events. @@ -19,9 +19,9 @@ class ManagerServiceProvider extends ServiceProvider { public function boot() { $this->package('barryvdh/laravel-translation-manager'); - } + } - /** + /** * Register the service provider. * * @return void @@ -71,7 +71,7 @@ public function register() */ public function provides() { - return array('translation-manager', + return array('translation-manager', 'translator', 'translation.loader', 'command.translation-manager.reset', 'command.translation-manager.import', 'command.translation-manager.find', diff --git a/src/Barryvdh/TranslationManager/TranslationServiceProvider.php b/src/Barryvdh/TranslationManager/TranslationServiceProvider.php index 457d47c..e8dff31 100644 --- a/src/Barryvdh/TranslationManager/TranslationServiceProvider.php +++ b/src/Barryvdh/TranslationManager/TranslationServiceProvider.php @@ -12,7 +12,6 @@ class TranslationServiceProvider extends BaseTranslationServiceProvider { */ public function register() { - $this->registerLoader(); $this->app->bindShared('translator', function($app) @@ -24,7 +23,7 @@ public function register() // configuration so we can easily get both of these values from there. $locale = $app['config']['app.locale']; - $trans = new Translator($loader, $locale); + $trans = new \Barryvdh\TranslationManager\Translator($loader, $locale); $trans->setFallback($app['config']['app.fallback_locale']); diff --git a/src/Barryvdh/TranslationManager/Translator.php b/src/Barryvdh/TranslationManager/Translator.php index 531ff83..7ac60b8 100644 --- a/src/Barryvdh/TranslationManager/Translator.php +++ b/src/Barryvdh/TranslationManager/Translator.php @@ -1,42 +1,84 @@ 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 = '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) : '') . ' '//. (!$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); } } - }