Skip to content

Commit

Permalink
Fix the import of subfolders on linux (#121)
Browse files Browse the repository at this point in the history
* Fix the import of subfolders on linux

Addresses #87

* Support more than 1 nesting

* Consistently manage the subgroup
  • Loading branch information
oliverpool authored and barryvdh committed Aug 17, 2016
1 parent be4c04b commit 4e70c98
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
38 changes: 20 additions & 18 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@ public function getIndex($group = null)
->with('deleteEnabled', $this->manager->getConfig('delete_enabled'));
}

public function getView($group, $sub_group = null)
public function getView()
{
if ($sub_group) {
return $this->getIndex($group.'/'.$sub_group);
}

$groups = func_get_args();
$group = implode('/', $groups);
return $this->getIndex($group);
}

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

public function postAdd(Request $request, $group, $sub_group = null)
public function postAdd(Request $request)
{
$keys = explode("\n", $request->get('keys'));

if ($sub_group) {
$group = $group . "/" . $sub_group;
}
$groups = func_get_args();
array_shift($groups); // remove the $request
$group = implode('/', $groups);

foreach($keys as $key){
$key = trim($key);
Expand All @@ -87,16 +85,19 @@ public function postAdd(Request $request, $group, $sub_group = null)
return redirect()->back();
}

public function postEdit(Request $request, $group, $sub_group = null)
public function postEdit(Request $request, $group)
{
if(!in_array($group, $this->manager->getConfig('exclude_groups'))) {
$groups = func_get_args();
array_shift($groups); // remove the $request
$group = implode('/', $groups);
$name = $request->get('name');
$value = $request->get('value');

list($locale, $key) = explode('|', $name, 2);
$translation = Translation::firstOrNew([
'locale' => $locale,
'group' => $sub_group ? $group . "/" . $sub_group: $group,
'group' => $group,
'key' => $key,
]);
$translation->value = (string) $value ?: null;
Expand All @@ -106,8 +107,11 @@ public function postEdit(Request $request, $group, $sub_group = null)
}
}

public function postDelete($group, $key, $sub_group = null)
public function postDelete()
{
$groups = func_get_args();
$key = array_pop($groups); // the last arg is the key
$group = implode('/', $groups);
if(!in_array($group, $this->manager->getConfig('exclude_groups')) && $this->manager->getConfig('delete_enabled')) {
Translation::where('group', $group)->where('key', $key)->delete();
return ['status' => 'ok'];
Expand All @@ -129,13 +133,11 @@ public function postFind()
return ['status' => 'ok', 'counter' => (int) $numFound];
}

public function postPublish($group, $sub_group = null)
public function postPublish()
{
if ($sub_group) {
$this->manager->exportTranslations($group.'/'.$sub_group);
} else {
$this->manager->exportTranslations($group);
}
$groups = func_get_args();
$group = implode('/', $groups);
$this->manager->exportTranslations($group);

return ['status' => 'ok'];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function importTranslations($replace = false)
continue;
}

$subLangPath = str_replace($langPath . "\\", "", $info['dirname']);
$subLangPath = str_replace($langPath . DIRECTORY_SEPARATOR, "", $info['dirname']);
if ($subLangPath != $langPath) {
$group = $subLangPath . "/" . $group;
}
Expand Down

0 comments on commit 4e70c98

Please sign in to comment.