From bcb1fa227d465c317ad338e9e433d55d9cc03176 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Tue, 17 Dec 2024 08:46:06 -0500 Subject: [PATCH] Fix bug related to aliasing default domain translations. (#4167) --- .../I18n/Translator/Loader/ExtendedIni.php | 2 +- .../Translator/Loader/ExtendedIniTest.php | 25 +++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/module/VuFind/src/VuFind/I18n/Translator/Loader/ExtendedIni.php b/module/VuFind/src/VuFind/I18n/Translator/Loader/ExtendedIni.php index 2f2544b156d..2bca3502c0c 100644 --- a/module/VuFind/src/VuFind/I18n/Translator/Loader/ExtendedIni.php +++ b/module/VuFind/src/VuFind/I18n/Translator/Loader/ExtendedIni.php @@ -194,7 +194,7 @@ public function load($locale, $filename) */ public function getLanguageFilename($locale, $domain) { - return empty($domain) + return (empty($domain) || $domain === 'default') ? $locale . '.ini' : $domain . '/' . $locale . '.ini'; } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/I18n/Translator/Loader/ExtendedIniTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/I18n/Translator/Loader/ExtendedIniTest.php index 5466cd87920..abf0305fc88 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/I18n/Translator/Loader/ExtendedIniTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/I18n/Translator/Loader/ExtendedIniTest.php @@ -172,11 +172,11 @@ public function testMissingPathStack(): void } /** - * Test alias behavior. + * Test alias behavior in default domain. * * @return void */ - public function testAliasing(): void + public function testAliasingInDefaultDomain(): void { $pathStack = [ realpath($this->getFixtureDir() . 'language/aliases'), @@ -195,6 +195,27 @@ public function testAliasing(): void ); } + /** + * Test alias behavior in non-default domain. + * + * @return void + */ + public function testAliasingInNonDefaultDomain(): void + { + $pathStack = [ + realpath($this->getFixtureDir() . 'language/aliases'), + ]; + $loader = new ExtendedIni($pathStack, 'en'); + $result = $loader->load('en', 'Domain'); + $this->assertEquals( + [ + 'bar' => 'Domain Translation', + 'foofoo' => 'Translation', + ], + (array)$result + ); + } + /** * Test circular alias infinite loop prevention. *