mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
ENHANCEMENT Added parameter to DBLocale->Nice()
ENHANCEMENT Added DBLocale->getNativeName() (from r93771) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@93941 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
22bc6827ae
commit
43dd296076
@ -14,11 +14,16 @@ class DBLocale extends Varchar {
|
||||
}
|
||||
|
||||
/**
|
||||
* See {@link getShortName()}.
|
||||
* See {@link getShortName()} and {@link getNativeName()}.
|
||||
*
|
||||
* @param Boolean $showNative Show a localized version of the name instead, based on the
|
||||
* field's locale value.
|
||||
* @return String
|
||||
*/
|
||||
function Nice() {
|
||||
function Nice($showNative=false) {
|
||||
if ($showNative) {
|
||||
return $this->getNativeName();
|
||||
}
|
||||
return $this->getShortName();
|
||||
}
|
||||
|
||||
@ -37,8 +42,22 @@ class DBLocale extends Varchar {
|
||||
return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return String
|
||||
*/
|
||||
function getLongName() {
|
||||
return i18n::get_locale_name($this->value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the localized name based on the field's value.
|
||||
* Example: "de_DE" returns "Deutsch".
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
function getNativeName() {
|
||||
$common_names = i18n::get_common_locales(true);
|
||||
return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
@ -8,5 +8,15 @@ class DBLocaleTest extends SapphireTest {
|
||||
$l = DBField::create('DBLocale', 'de_DE');
|
||||
$this->assertEquals($l->Nice(), 'German');
|
||||
}
|
||||
|
||||
function testNiceNative() {
|
||||
$l = DBField::create('DBLocale', 'de_DE');
|
||||
$this->assertEquals($l->Nice(true), 'Deutsch');
|
||||
}
|
||||
|
||||
function testNativeName() {
|
||||
$l = DBField::create('DBLocale', 'de_DE');
|
||||
$this->assertEquals($l->getNativeName(), 'Deutsch');
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user