Skip to content
This repository has been archived by the owner on Jul 16, 2020. It is now read-only.

Commit

Permalink
Relative translations are not loaded in the proper locale (#54)
Browse files Browse the repository at this point in the history
* Relative translations are not loaded in the proper locale

e.g. if you have a file:
```PHP
<?php
return [
    ‘key’ => __(‘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.
  • Loading branch information
sporchia authored and martinlindhe committed Nov 26, 2018
1 parent 32dc7f8 commit a1cbc8b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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()) {
Expand Down

0 comments on commit a1cbc8b

Please sign in to comment.