Skip to content

Commit

Permalink
clean up inPlaceEdit button and link generation
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Mar 26, 2015
1 parent 9d9f71a commit c40ef29
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
31 changes: 22 additions & 9 deletions src/Barryvdh/TranslationManager/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ function excludedPageEditGroup($group)
* @return null|Translation
*/
public
function missingKey($namespace, $group, $key, $useLottery = false)
function missingKey($namespace, $group, $key, $useLottery = false, $findOrNew = false)
{
$group = $namespace && $namespace !== '*' ? $namespace . '::' . $group : $group;

if (!in_array($group, $this->config()['exclude_groups']) && $this->config()['log_missing_keys'])
{
$lottery = 1;
Expand All @@ -75,11 +77,22 @@ function missingKey($namespace, $group, $key, $useLottery = false)

if ($lottery === 1)
{
$translation = Translation::firstOrCreate(array(
'locale' => $this->app['config']['app.locale'],
'group' => $group,
'key' => $key,
));
if ($findOrNew)
{
$translation = Translation::firstOrNew(array(
'locale' => $this->app['config']['app.locale'],
'group' => $group,
'key' => $key,
));
}
else
{
$translation = Translation::firstOrCreate(array(
'locale' => $this->app['config']['app.locale'],
'group' => $group,
'key' => $key,
));
}

return $translation;
}
Expand All @@ -98,7 +111,7 @@ function importTranslationLocale($replace = false, $locale, $langPath, $namespac
$info = pathinfo($file);
$group = $info['filename'];

if (in_array($package.$group, $this->config()['exclude_groups']))
if (in_array($package . $group, $this->config()['exclude_groups']))
{
continue;
}
Expand All @@ -109,7 +122,7 @@ function importTranslationLocale($replace = false, $locale, $langPath, $namespac
$value = (string)$value;
$translation = Translation::firstOrNew(array(
'locale' => $locale,
'group' => $package.$group,
'group' => $package . $group,
'key' => $key,
));

Expand Down Expand Up @@ -296,7 +309,7 @@ function exportTranslations($group)
$packgroup = explode('::', $group, 2);
$package = array_shift($packgroup);
$packgroup = array_shift($packgroup);
$path = $this->app->make('path') . '/lang/packages/' . $locale . '/'. $package . '/' . $packgroup . '.php';
$path = $this->app->make('path') . '/lang/packages/' . $locale . '/' . $package . '/' . $packgroup . '.php';
}
else
{
Expand Down
16 changes: 14 additions & 2 deletions src/Barryvdh/TranslationManager/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ function inPlaceEditLink($t, $withDiff = false)
return '';
}

public
function getInPlaceEditLink($key, array $replace = array(), $locale = null){
list($namespace, $group, $item) = $this->parseKey($key);

if ($this->manager && $group && $item && !$this->manager->excludedPageEditGroup($group))
{
$t = $this->manager->missingKey($namespace, $group, $item);
return $this->inPlaceEditLink($t);
}
return '';
}

/**
* Get the translation for the given key.
*
Expand All @@ -85,9 +97,9 @@ function get($key, array $replace = array(), $locale = null)
{
list($namespace, $group, $item) = $this->parseKey($key);

if ($this->manager && $namespace === '*' && $group && $item && !$this->manager->excludedPageEditGroup($group))
if ($this->manager && $group && $item && !$this->manager->excludedPageEditGroup($group))
{
$t = $this->manager->missingKey($namespace, $group, $item);
$t = $this->manager->missingKey($namespace, $group, $item, false, true);
return $this->inPlaceEditLink($t);
}
}
Expand Down

0 comments on commit c40ef29

Please sign in to comment.