Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions config/translation-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* This setting enables or disables the web interface and its routes.
*/
'webinterface' => true,
'webinterface' => env('APP_DEBUG', false),

/**
* This is the prefix for on which URI the Translations Manager will
Expand All @@ -28,12 +28,15 @@
'disable_debugbar' => true,

/**
* - Force translations to be cached, even in Debug Mode.
* - And disables the collection of new keys.
* This can be used to prevent lots of queries from
* happening.
*/
'minimal' => false,
'cache' => !env('APP_DEBUG', false),

/**
* Collect new keys
*/
'collect' => env('APP_DEBUG', false),

/**
* Use locales from files as a fallback option. Be aware that
Expand Down
4 changes: 2 additions & 2 deletions src/DatabaseLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public function addNamespace($namespace, $hint) {}
*/
public function addTranslation($locale, $group, $key)
{
if(!\Config::get('app.debug') || \Config::get('translation-db.minimal')) return;
if(!\Config::get('translation-db.collect')) return;

// Extract the real key from the translation.
if (preg_match("/^{$group}\.(.*?)$/sm", $key, $match)) {
if (preg_match("/^{$group}\\.(.*?)$/sm", $key, $match)) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've seem to have added an extra slash. This slash however will break functionality. The single slash is intended to restrain the following dot from being counted as a wildcard character. Adding an extra slash would result in the dot being a wildcard.

$name = $match[1];
} else {
throw new TranslationException('Could not extract key from translation.');
Expand Down
3 changes: 1 addition & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public function boot()
$this->loadViewsFrom(__DIR__.'/../views', 'translation');
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'translation');

// Only in debug mode the translations interface should be available.
if($this->app['config']->get('app.debug') && $this->app['config']->get('translation-db.webinterface')) {
if($this->app['config']->get('translation-db.webinterface')) {
$routeConfig = [
'namespace' => 'Hpolthof\Translation\Controllers',
'prefix' => $this->app['config']->get('translation-db.route_prefix'),
Expand Down
2 changes: 1 addition & 1 deletion src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function load($namespace, $group, $locale)
// This will allow legacy support.
if(!self::isNamespaced($namespace)) {
// If debug is off then cache the result forever to ensure high performance.
if(!\Config::get('app.debug') || \Config::get('translation-db.minimal')) {
if(\Config::get('translation-db.cache')) {
$that = $this;
$lines = \Cache::rememberForever('__translations.'.$locale.'.'.$group, function() use ($that, $locale, $group, $namespace) {
return $that->loadFromDatabase($namespace, $group, $locale);
Expand Down