diff --git a/framework/yii/helpers/BaseFileHelper.php b/framework/yii/helpers/BaseFileHelper.php index 90d6117..36591ae 100644 --- a/framework/yii/helpers/BaseFileHelper.php +++ b/framework/yii/helpers/BaseFileHelper.php @@ -68,7 +68,7 @@ class BaseFileHelper if ($language === $sourceLanguage) { return $file; } - $desiredFile = dirname($file) . DIRECTORY_SEPARATOR . $sourceLanguage . DIRECTORY_SEPARATOR . basename($file); + $desiredFile = dirname($file) . DIRECTORY_SEPARATOR . $language . DIRECTORY_SEPARATOR . basename($file); return is_file($desiredFile) ? $desiredFile : $file; } diff --git a/tests/unit/framework/helpers/FileHelperTest.php b/tests/unit/framework/helpers/FileHelperTest.php index 3b5f49e..8ad977f 100644 --- a/tests/unit/framework/helpers/FileHelperTest.php +++ b/tests/unit/framework/helpers/FileHelperTest.php @@ -313,4 +313,29 @@ class FileHelperTest extends TestCase { $this->assertEquals(DIRECTORY_SEPARATOR.'home'.DIRECTORY_SEPARATOR.'demo', FileHelper::normalizePath('/home\demo/')); } + + public function testLocalizedDirectory() + { + $this->createFileStructure([ + 'views' => [ + 'faq.php' => 'English FAQ', + 'de-DE' => [ + 'faq.php' => 'German FAQ', + ], + ], + ]); + $viewFile = $this->testFilePath . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'faq.php'; + $sourceLanguage = 'en-US'; + + // Source language and target language are same. The view path should be unchanged. + $currentLanguage = $sourceLanguage; + $this->assertSame($viewFile, FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage)); + + // Source language and target language are different. The view path should be changed. + $currentLanguage = 'de-DE'; + $this->assertSame( + $this->testFilePath . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $currentLanguage . DIRECTORY_SEPARATOR . 'faq.php', + FileHelper::localize($viewFile, $currentLanguage, $sourceLanguage) + ); + } }