Skip to content

Commit

Permalink
Improve getTranslationsFile failsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarpsvo committed Nov 23, 2020
1 parent 28eec35 commit 26af343
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/LoadsNovaTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,20 @@ private function loadLaravelTranslationsForLocale($locale, $pckgTransDir, $pckgN

private function getTranslationsFile($locale, $from, $packageTranslationsDir, $packageName)
{
if (empty($locale)) return null;

$fileDir = $from === 'local'
? $packageTranslationsDir
: resource_path("lang/vendor/{$packageName}");

$filePath = $locale ? "$fileDir/{$locale}.json" : $fileDir;
$filePath = "$fileDir/{$locale}.json";

$localeFileExists = File::exists($filePath);
return $localeFileExists ? $filePath : null;
if (!$localeFileExists) return null;

// Test if file is valid JSON
$fileContents = json_decode(file_get_contents($filePath), true);

return !empty($fileContents) ? $filePath : null;
}
}

0 comments on commit 26af343

Please sign in to comment.