Skip to content

Commit

Permalink
Check if array
Browse files Browse the repository at this point in the history
  • Loading branch information
barryvdh committed Apr 15, 2015
1 parent c610c95 commit 1c2621d
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,31 @@ public function importTranslations($replace = false)
continue;
}

$translations = array_dot(\Lang::getLoader()->load($locale, $group));
foreach($translations as $key => $value){
$value = (string) $value;
$translation = Translation::firstOrNew(array(
'locale' => $locale,
'group' => $group,
'key' => $key,
));

// Check if the database is different then the files
$newStatus = $translation->value === $value ? Translation::STATUS_SAVED : Translation::STATUS_CHANGED;
if($newStatus !== (int) $translation->status){
$translation->status = $newStatus;
}

// Only replace when empty, or explicitly told so
if($replace || !$translation->value){
$translation->value = $value;
$translations = \Lang::getLoader()->load($locale, $group);
if ($translations && is_array($translation)) {
foreach(array_dot($translations) as $key => $value){
$value = (string) $value;
$translation = Translation::firstOrNew(array(
'locale' => $locale,
'group' => $group,
'key' => $key,
));

// Check if the database is different then the files
$newStatus = $translation->value === $value ? Translation::STATUS_SAVED : Translation::STATUS_CHANGED;
if($newStatus !== (int) $translation->status){
$translation->status = $newStatus;
}

// Only replace when empty, or explicitly told so
if($replace || !$translation->value){
$translation->value = $value;
}

$translation->save();

$counter++;
}

$translation->save();

$counter++;
}
}
}
Expand Down

0 comments on commit 1c2621d

Please sign in to comment.