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:
Ingo Schommer 2009-11-30 00:44:46 +00:00
parent 22bc6827ae
commit 43dd296076
2 changed files with 32 additions and 3 deletions

View File

@ -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 * @return String
*/ */
function Nice() { function Nice($showNative=false) {
if ($showNative) {
return $this->getNativeName();
}
return $this->getShortName(); return $this->getShortName();
} }
@ -37,8 +42,22 @@ class DBLocale extends Varchar {
return (isset($common_names[$this->value])) ? $common_names[$this->value] : false; return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
} }
/**
* @return String
*/
function getLongName() { function getLongName() {
return i18n::get_locale_name($this->value); 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;
}
} }
?> ?>

View File

@ -8,5 +8,15 @@ class DBLocaleTest extends SapphireTest {
$l = DBField::create('DBLocale', 'de_DE'); $l = DBField::create('DBLocale', 'de_DE');
$this->assertEquals($l->Nice(), 'German'); $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');
}
} }
?> ?>