From cee71dc73e176eb755007f2a062e27675a98d92f Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Tue, 13 Nov 2018 16:09:56 +0100 Subject: [PATCH 1/4] - remove key check on file level Signed-off-by: Christoph Potas --- system/Language/Language.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Language/Language.php b/system/Language/Language.php index f23fc3e27924..3a5bb9a95e4f 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] ) ) { $this->load($file, $this->locale); } return [ $file, - $this->language[$this->locale][$line] ?? $line, + $line, ]; } From 4c02deb27892490332f44f1d1887021d0d9fc17b Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Tue, 13 Nov 2018 16:33:03 +0100 Subject: [PATCH 2/4] + add test case Signed-off-by: Christoph Potas --- tests/system/Language/LanguageTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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')); + } } From fc1c9003b14c0ef80350cc18ab1dfe4c1a85be6a Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Tue, 13 Nov 2018 16:52:42 +0100 Subject: [PATCH 3/4] ~ use array_key_exists instead of isset Signed-off-by: Christoph Potas --- system/Language/Language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Language/Language.php b/system/Language/Language.php index 3a5bb9a95e4f..719738818670 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -152,7 +152,7 @@ protected function parseLine(string $line): array $file = substr($line, 0, strpos($line, '.')); $line = substr($line, strlen($file) + 1); - if (! isset( $this->language[$this->locale][$file] ) ) + if (! array_key_exists( $line, $this->language[$this->locale][$file] ) ) { $this->load($file, $this->locale); } From 4e8c2d954e67bc01a10f4dec93177d38ec4686dc Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Tue, 13 Nov 2018 17:01:08 +0100 Subject: [PATCH 4/4] + added local & file check Signed-off-by: Christoph Potas --- system/Language/Language.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Language/Language.php b/system/Language/Language.php index 719738818670..e1897bfb0303 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -152,7 +152,7 @@ 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[$this->locale][$file] ) ) + if (! isset($this->language[$this->locale][$file]) || ! array_key_exists($line, $this->language[$this->locale][$file])) { $this->load($file, $this->locale); }