diff --git a/system/Language/Language.php b/system/Language/Language.php index 9235610f1171..77125220b5ca 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -163,6 +163,24 @@ public function getLine(string $line, array $args = []) } } + if ($output === null) + { + unset($current); + foreach (explode('.', $parsedLine) as $row) + { + if (! isset($current)) + { + $current = $this->language[$this->locale][$file] ?? null; + } + + if (isset($current[$row][substr($parsedLine, strlen($row) + 1)])) + { + $output = $current[$row][substr($parsedLine, strlen($row) + 1)]; + break; + } + } + } + if ($output === null && strpos($this->locale, '-')) { [$locale] = explode('-', $this->locale, 2); diff --git a/tests/_support/Language/en/Foo.php b/tests/_support/Language/en/Foo.php index 56e23d0f6bef..af78da682fa5 100644 --- a/tests/_support/Language/en/Foo.php +++ b/tests/_support/Language/en/Foo.php @@ -4,4 +4,7 @@ 'bar' => 'Foo Bar Translated', 'bar.min_length1' => 'The {field} field is very short.', 'bar.min_length2' => 'Supplied value ({value}) for {field} must have at least {param} characters.', + 'bar' => [ + 'min.length' => 'The {field} field is very short.', + ], ]; diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index f32316b8b8be..86ca127a1861 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -321,4 +321,13 @@ public function testLanguageNestedArrayDefinition() $this->assertEquals('e', $lang->getLine('Nested.a.b.c.d')); } + public function testLanguageKeySeparatedByDot() + { + $lang = new SecondMockLanguage('en'); + $lang->loadem('Foo', 'en'); + + $this->assertEquals('The fieldname field is very short.', $lang->getLine('Foo.bar.min_length1', ['field' => 'fieldname'])); + $this->assertEquals('The fieldname field is very short.', $lang->getLine('Foo.bar.min.length', ['field' => 'fieldname'])); + } + }