mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-03 22:12:37 +08:00
- Fixed BaseFileHelper::localize docs.
- DbMessageSource now performs UNION ALL. - Fixed message merging for php and po. - Updated tests.
This commit is contained in:
@ -42,8 +42,8 @@ class BaseFileHelper
|
|||||||
* The searching is based on the specified language code. In particular,
|
* The searching is based on the specified language code. In particular,
|
||||||
* a file with the same name will be looked for under the subdirectory
|
* a file with the same name will be looked for under the subdirectory
|
||||||
* whose name is the same as the language code. For example, given the file "path/to/view.php"
|
* whose name is the same as the language code. For example, given the file "path/to/view.php"
|
||||||
* and language code "zh_CN", the localized file will be looked for as
|
* and language code "zh-CN", the localized file will be looked for as
|
||||||
* "path/to/zh_CN/view.php". If the file is not found, it will try a fallback with just a language code that is
|
* "path/to/zh-CN/view.php". If the file is not found, it will try a fallback with just a language code that is
|
||||||
* "zh" i.e. "path/to/zh/view.php". If it is not found as well the original file will be returned.
|
* "zh" i.e. "path/to/zh/view.php". If it is not found as well the original file will be returned.
|
||||||
*
|
*
|
||||||
* If the target and the source language codes are the same,
|
* If the target and the source language codes are the same,
|
||||||
|
|||||||
@ -162,7 +162,7 @@ class DbMessageSource extends MessageSource
|
|||||||
->andWhere('t2.id NOT IN (SELECT id FROM '.$this->messageTable.' WHERE language = :language)')
|
->andWhere('t2.id NOT IN (SELECT id FROM '.$this->messageTable.' WHERE language = :language)')
|
||||||
->params([':category' => $category, ':language' => $language, ':fallbackLanguage' => $fallbackLanguage]);
|
->params([':category' => $category, ':language' => $language, ':fallbackLanguage' => $fallbackLanguage]);
|
||||||
|
|
||||||
$mainQuery->union($fallbackQuery);
|
$mainQuery->union($fallbackQuery, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$messages = $mainQuery->createCommand($this->db)->queryAll();
|
$messages = $mainQuery->createCommand($this->db)->queryAll();
|
||||||
|
|||||||
@ -73,8 +73,8 @@ class GettextMessageSource extends MessageSource
|
|||||||
} else if (empty($messages)) {
|
} else if (empty($messages)) {
|
||||||
return $fallbackMessages;
|
return $fallbackMessages;
|
||||||
} else if (!empty($fallbackMessages)) {
|
} else if (!empty($fallbackMessages)) {
|
||||||
foreach ($messages as $key => $value) {
|
foreach ($fallbackMessages as $key => $value) {
|
||||||
if (empty($value) && !empty($fallbackMessages[$key])) {
|
if (!empty($value) && empty($messages[$key])) {
|
||||||
$messages[$key] = $fallbackMessages[$key];
|
$messages[$key] = $fallbackMessages[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,8 +76,8 @@ class PhpMessageSource extends MessageSource
|
|||||||
} else if (empty($messages)) {
|
} else if (empty($messages)) {
|
||||||
return $fallbackMessages;
|
return $fallbackMessages;
|
||||||
} else if (!empty($fallbackMessages)) {
|
} else if (!empty($fallbackMessages)) {
|
||||||
foreach ($messages as $key => $value) {
|
foreach ($fallbackMessages as $key => $value) {
|
||||||
if (empty($value) && !empty($fallbackMessages[$key])) {
|
if (!empty($value) && empty($messages[$key])) {
|
||||||
$messages[$key] = $fallbackMessages[$key];
|
$messages[$key] = $fallbackMessages[$key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
tests/unit/data/i18n/messages/de/test.php
Normal file
7
tests/unit/data/i18n/messages/de/test.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
return [
|
||||||
|
'Hello world!' => 'Hallo Welt!',
|
||||||
|
];
|
||||||
7
tests/unit/data/i18n/messages/ru/test.php
Normal file
7
tests/unit/data/i18n/messages/ru/test.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
return [
|
||||||
|
'The dog runs fast.' => 'Собака бегает быстро.',
|
||||||
|
];
|
||||||
@ -40,8 +40,18 @@ class I18NTest extends TestCase
|
|||||||
public function testTranslate()
|
public function testTranslate()
|
||||||
{
|
{
|
||||||
$msg = 'The dog runs fast.';
|
$msg = 'The dog runs fast.';
|
||||||
$this->assertEquals('The dog runs fast.', $this->i18n->translate('test', $msg, [], 'en-US'));
|
|
||||||
|
// source = target. Should be returned as is.
|
||||||
|
$this->assertEquals('The dog runs fast.', $this->i18n->translate('test', $msg, [], 'en'));
|
||||||
|
|
||||||
|
// exact match
|
||||||
$this->assertEquals('Der Hund rennt schnell.', $this->i18n->translate('test', $msg, [], 'de-DE'));
|
$this->assertEquals('Der Hund rennt schnell.', $this->i18n->translate('test', $msg, [], 'de-DE'));
|
||||||
|
|
||||||
|
// fallback to just language code with absent exact match
|
||||||
|
$this->assertEquals('Собака бегает быстро.', $this->i18n->translate('test', $msg, [], 'ru-RU'));
|
||||||
|
|
||||||
|
// fallback to just langauge code with present exact match
|
||||||
|
$this->assertEquals('Hallo Welt!', $this->i18n->translate('test', 'Hello world!', [], 'de-DE'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTranslateParams()
|
public function testTranslateParams()
|
||||||
|
|||||||
Reference in New Issue
Block a user