From a1cbc8b59980120e5e47b6066712b8c0a25f2c9e Mon Sep 17 00:00:00 2001 From: Salvatore Date: Mon, 26 Nov 2018 05:21:30 -0500 Subject: [PATCH] Relative translations are not loaded in the proper locale (#54) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Relative translations are not loaded in the proper locale e.g. if you have a file: ```PHP __(‘other_file.other_key’), ]; ``` it is translated to the base locale and not the current locale, this should fix that. * updated so tests don't fail since the unit tests aren’t run inside of Laravel scope, this will check that App is available before calling setLocale on it. --- src/Generator.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Generator.php b/src/Generator.php index 369f586..2d24689 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -59,6 +59,9 @@ public function generateFromPath($path, $umd = null, $withVendor = false) $fileinfo = new \SplFileInfo($fileName); $noExt = $this->removeExtension($fileinfo->getFilename()); + if (class_exists('App')) { + App::setLocale($noExt); + } if ($fileinfo->isDir()) { $local = $this->allocateLocaleArray($fileinfo->getRealPath()); @@ -113,8 +116,10 @@ public function generateMultiple($path, $umd = null) && !in_array($fileinfo->getFilename(), ['vendor']) ) { $noExt = $this->removeExtension($fileinfo->getFilename()); - if (!in_array($noExt, $this->availableLocales)) { + if (class_exists('App')) { App::setLocale($noExt); + } + if (!in_array($noExt, $this->availableLocales)) { $this->availableLocales[] = $noExt; } if ($fileinfo->isDir()) {