mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Refactoring I18n::translate() to return time format string or arrays when category is LC_TIME
Tests added
This commit is contained in:
parent
589972d581
commit
a980f72364
2 changed files with 44 additions and 0 deletions
|
@ -164,6 +164,10 @@ class I18n extends Object {
|
|||
$_this->__cache = true;
|
||||
}
|
||||
|
||||
if ($_this->category == 'LC_TIME') {
|
||||
return $_this->__translateTime($singular,$domain);
|
||||
}
|
||||
|
||||
if (!isset($count)) {
|
||||
$plurals = 0;
|
||||
} elseif (!empty($_this->__domains[$_this->category][$_this->__lang][$domain]["%plural-c"]) && $_this->__noLocale === false) {
|
||||
|
@ -448,6 +452,14 @@ class I18n extends Object {
|
|||
return $this->__domains[$this->category][$this->__lang][$domain] = array_merge($merge ,$translations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a locale definition file following the POSIX standard
|
||||
*
|
||||
* @param string $file file to load
|
||||
* @param string $domain Domain where locale definitions will be stored
|
||||
* @return void
|
||||
* @access private
|
||||
*/
|
||||
function __loadLocaleDefinition($file, $domain = null) {
|
||||
$_this =& I18N::getInstance();
|
||||
$comment = '#';
|
||||
|
@ -503,6 +515,13 @@ class I18n extends Object {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary function to parse a symbol from a locale definition file
|
||||
*
|
||||
* @param string $string Symbol to be parsed
|
||||
* @return string parsed symbol
|
||||
* @access private
|
||||
*/
|
||||
function __parseLiteralValue($string) {
|
||||
$string = $string[1];
|
||||
if (substr($string,0,2) === $this->__escape . 'x') {
|
||||
|
@ -524,6 +543,23 @@ class I18n extends Object {
|
|||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Time format definition from corresponding domain
|
||||
*
|
||||
* @param string $format Format to be translated
|
||||
* @param string $domain Domain where format is stored
|
||||
* @return mixed translated format string if only value or array of translated strings for corresponding format.
|
||||
* @access private
|
||||
*/
|
||||
function __translateTime($format,$domain) {
|
||||
if (!empty($this->__domains['LC_TIME'][$this->__lang][$domain][$format])) {
|
||||
if (($trans = $this->__domains[$this->category][$this->__lang][$domain][$format])) {
|
||||
return $trans;
|
||||
}
|
||||
}
|
||||
return $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Object destructor
|
||||
*
|
||||
|
|
|
@ -2594,6 +2594,14 @@ class I18nTest extends CakeTestCase {
|
|||
$result = __c('d_fmt', 5, true);
|
||||
$expected = '%m/%d/%Y';
|
||||
$this->assertEqual($result,$expected);
|
||||
|
||||
$result = __c('am_pm',5,true);
|
||||
$expected = array('AM','PM');
|
||||
$this->assertEqual($result,$expected);
|
||||
|
||||
$result = __c('abmon',5,true);
|
||||
$expected = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
|
||||
$this->assertEqual($result,$expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue