Permalink
Browse files

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
  • Loading branch information...
1 parent 22bc682 commit 43dd296076975cd91d143f7da0b9c43db6672218 @chillu chillu committed Nov 30, 2009
Showing with 32 additions and 3 deletions.
  1. +22 −3 core/model/fieldtypes/DBLocale.php
  2. +10 −0 tests/model/DBLocaleTest.php
@@ -14,11 +14,16 @@ function __construct($name, $size = 16) {
}
/**
- * 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 @@ function getShortName() {
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 @@ function testNice() {
$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');
+ }
}
?>

0 comments on commit 43dd296

Please sign in to comment.