Skip to content

Commit

Permalink
Merge pull request #1480 from puschie286/FixLanguageKeyFileConfusion
Browse files Browse the repository at this point in the history
Fix Language Key-File confusion
  • Loading branch information
lonnieezell authored Nov 14, 2018
2 parents 4467fac + 4e8c2d9 commit cf42968
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions system/Language/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ protected function parseLine(string $line): array
$file = substr($line, 0, strpos($line, '.'));
$line = substr($line, strlen($file) + 1);

if (! array_key_exists($line, $this->language))
if (! isset($this->language[$this->locale][$file]) || ! array_key_exists($line, $this->language[$this->locale][$file]))
{
$this->load($file, $this->locale);
}

return [
$file,
$this->language[$this->locale][$line] ?? $line,
$line,
];
}

Expand Down
17 changes: 17 additions & 0 deletions tests/system/Language/LanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,21 @@ public function testLanguageFileLoadingReturns()
$this->assertEquals(1, count($lang->loaded()));
}

//--------------------------------------------------------------------

public function testLanguageSameKeyAndFileName()
{
$lang = new MockLanguage('en');

// first file data | example.message
$lang->setData(['message' => 'This is an example message']);

// force loading data into file Example
$this->assertEquals('This is an example message', $lang->getLine('example.message'));

// second file data | another.example
$lang->setData(['example' => 'Another example']);

$this->assertEquals('Another example', $lang->getLine('another.example'));
}
}

0 comments on commit cf42968

Please sign in to comment.