Skip to content

Commit

Permalink
Improved "lg" function
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniels Grietins committed Feb 17, 2018
1 parent 05789e0 commit f45ab53
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Helpers/Global.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@ function trans_model($row, Language $language, $attribute = null): String
* @param $value
* @return String
*/
function lg($key, array $replace = [], $locale = null, $value = null): String
function lg($key, $replace = [], $locale = null, $value = null): String
{
$createTranslations = config('translations.create_translations_on_the_fly', false);

if ($createTranslations) {

$translations = cache('translations');
$languages = languages();
if (isset($locale) && !$languages->where('iso_code', $locale)) {
if (isset($locale) && !$languages->where('iso_code', $locale)->count()) {
$value = $locale;
}
if(!$locale && !$value && !is_array($replace)) {
$value = $replace;
}
$fallbackIsoCode = $languages->where('is_fallback', 1)->first()->iso_code;
$transKey = $fallbackIsoCode . '.' . $key;

if (!isset($translations[$transKey]) && isset($value)) {
if (!isset($translations[$transKey])) {
$translations = [
'key' => $key,
];
Expand All @@ -70,6 +73,10 @@ function lg($key, array $replace = [], $locale = null, $value = null): String
}
}

if(!is_array($replace)) {
$replace = [];
}

return trans($key, $replace, $locale);
}
}

0 comments on commit f45ab53

Please sign in to comment.