diff --git a/system/Language/Language.php b/system/Language/Language.php index f23fc3e27924..e1897bfb0303 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -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, ]; } diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index 4dfa02579a8e..89f364febede 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -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')); + } }