Browse Source

Fixes #1497 (wrong file rendered if language != sourceLanguage)

tags/2.0.0-beta
Florian Fackler 11 years ago
parent
commit
ff7c25ea7b
  1. 2
      framework/yii/helpers/BaseFileHelper.php
  2. 25
      tests/unit/framework/helpers/FileHelperTest.php

2
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;
}

25
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)
);
}
}

Loading…
Cancel
Save