From 4737956cf2e4b95369a911a7fd5668891746bd3b Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Tue, 12 May 2026 01:58:29 +0800 Subject: [PATCH] fix: restore deep dot-notation traversal in `Language::getLine()` --- system/Language/Language.php | 4 ++-- tests/system/Language/LanguageTest.php | 13 +++++++++++++ user_guide_src/source/changelogs/v4.7.3.rst | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/system/Language/Language.php b/system/Language/Language.php index 652d17a5b68d..1964c91aebd9 100644 --- a/system/Language/Language.php +++ b/system/Language/Language.php @@ -134,7 +134,7 @@ public function getLine(string $line, array $args = []) } /** - * @return list|string|null + * @return array|string|null */ protected function getTranslationOutput(string $locale, string $file, string $parsedLine) { @@ -160,7 +160,7 @@ protected function getTranslationOutput(string $locale, string $file, string $pa } } - if ($output !== null && ! is_array($output)) { + if ($output !== null) { return $output; } } diff --git a/tests/system/Language/LanguageTest.php b/tests/system/Language/LanguageTest.php index 749a30e88b3d..6233941e7d75 100644 --- a/tests/system/Language/LanguageTest.php +++ b/tests/system/Language/LanguageTest.php @@ -381,6 +381,19 @@ public function testLanguageNestedArrayDefinition(): void $this->assertSame('e', $lang->getLine('Nested.a.b.c.d')); } + /** + * @see https://github.com/codeigniter4/CodeIgniter4/issues/10187 + */ + public function testLanguageNestedArrayDefinitionReturnsIntermediateArrays(): void + { + $lang = new SecondMockLanguage('en'); + $lang->loadem('Nested', 'en'); + + $this->assertSame(['b' => ['c' => ['d' => 'e']]], $lang->getLine('Nested.a')); + $this->assertSame(['c' => ['d' => 'e']], $lang->getLine('Nested.a.b')); + $this->assertSame(['d' => 'e'], $lang->getLine('Nested.a.b.c')); + } + public function testLanguageKeySeparatedByDot(): void { $lang = new SecondMockLanguage('en'); diff --git a/user_guide_src/source/changelogs/v4.7.3.rst b/user_guide_src/source/changelogs/v4.7.3.rst index f3653336233d..dbc930e12304 100644 --- a/user_guide_src/source/changelogs/v4.7.3.rst +++ b/user_guide_src/source/changelogs/v4.7.3.rst @@ -46,6 +46,7 @@ Bugs Fixed - **Database:** Fixed a bug where the PostgreSQL driver's ``increment()`` and ``decrement()`` methods were not working for numeric columns. - **Database:** Fixed a bug where the SQLSRV driver's decrement method was adding instead of subtracting the decrement value when ``$castTextToInt`` was false. - **Kint:** Fixed a bug where stale Content Security Policy nonces were reused in worker mode, causing browser CSP violations for Debug Toolbar assets. +- **Language:** Fixed a bug where ``Language::getLine()`` returned the literal dot-notation key instead of the nested array value when the requested key resolved to an intermediate array three or more levels deep. - **Toolbar:** Fixed a bug where the Logs collector raised an undefined property error when using a third-party PSR-3 logger. - **Time:** Fixed a bug where ``Time::createFromTimestamp()`` could fail for microsecond timestamps when ``LC_NUMERIC`` used a comma decimal separator. - **Validation:** Fixed a bug where ``Validation::getValidated()`` dropped fields whose validated value was explicitly ``null``.