Skip to content

Commit

Permalink
Slight change in code
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedBHameed committed Nov 15, 2018
1 parent 843bea5 commit 2a49923
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions resources/assets/js/Snippet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
<div class="snippet__actions">
<div
class="snippet__toggle"
@click="toggle">Aktualisieren</div>
@click="toggle">Edit</div>
<div
class="snippet__save"
@click="save"
v-show="editorToggleState && showSave">Speichern</div>
v-show="editorToggleState && showSave">Update</div>
</div>
</div>
<div
Expand Down
4 changes: 2 additions & 2 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function update(Request $request, Snippet $snippet)
$path = [$snippet->locale, $snippet->namespace, $snippet->key];
$storeKey = implode('/', $path);
$snippet->save();
$this->updateCache($storeKey, $snippet->value);
self::updateCache($storeKey, $snippet->value);
}

protected function loadLocales()
Expand All @@ -70,7 +70,7 @@ protected function loadLocales()
return array_unique($locales);
}

private function updateCache($key, $value) {
static function updateCache($key, $value) {
if( Cache::has($key) ) {
Cache::forget($key);
}
Expand Down
15 changes: 10 additions & 5 deletions src/SnippetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public function __construct(Application $app)
$this->app = $app;
}

private function getKeyName($locale, $key) {
$path = [$this->getLocale($locale), $this->namespace, $key];
return implode('/', $path);
}

/**
* @param String $locale
* @return String
Expand All @@ -34,16 +39,15 @@ public function setNamespace($namespace)
$this->namespace = $namespace;
}

public function get($key, $default = 'No found translation', $namespace = null, $locale = null)
public function get($key, $default = '', $namespace = null, $locale = null)
{
if (null !== $namespace) {
$this->namespace = $namespace;
}

$locale = $this->getLocale($locale);
$path = [$this->getLocale($locale), $this->namespace, $key];
$storeKey = implode('/', $path);

$storeKey = $this->getKeyName($locale, $key);
$default = $default ? $default : $storeKey;
$manager = $this;
$namespace = $this->namespace;

Expand All @@ -53,9 +57,10 @@ public function get($key, $default = 'No found translation', $namespace = null,
return $snippet;
}

public function fetch($namespace, $key = null, $default = 'No found translation', $locale = null)
public function fetch($namespace, $key = null, $default = '', $locale = null)
{
$locale = $this->getLocale($locale);
$default = $this->getKeyName($locale, $key);
$query = DB::table('ms_snippets');
if ($key) {
$query->where('key', $key);
Expand Down

0 comments on commit 2a49923

Please sign in to comment.