silverstripe-framework/ORM/FieldType/DBLocale.php

69 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace SilverStripe\ORM\FieldType;
use i18n;
/**
* Locale database field, mainly used in {@link Translatable} extension.
2014-08-15 08:53:05 +02:00
*
* @todo Allowing showing locale values in different languages through Nice()
2014-08-15 08:53:05 +02:00
*
* @package framework
* @subpackage orm
*/
class DBLocale extends DBVarchar {
2014-08-15 08:53:05 +02:00
2016-05-16 06:16:28 +02:00
public function __construct($name = null, $size = 16) {
parent::__construct($name, $size);
}
/**
* See {@link getShortName()} and {@link getNativeName()}.
2014-08-15 08:53:05 +02:00
*
* @param Boolean $showNative Show a localized version of the name instead, based on the
* field's locale value.
* @return String
*/
public function Nice($showNative=false) {
if ($showNative) {
return $this->getNativeName();
}
return $this->getShortName();
}
2014-08-15 08:53:05 +02:00
public function RFC1766() {
return i18n::convert_rfc1766($this->value);
}
2014-08-15 08:53:05 +02:00
/**
* Resolves the locale to a common english-language
* name through {@link i18n::get_common_locales()}.
2014-08-15 08:53:05 +02:00
*
* @return String
*/
public function getShortName() {
$common_names = i18n::get_common_locales();
return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
}
2014-08-15 08:53:05 +02:00
/**
* @return String
*/
public function getLongName() {
return i18n::get_locale_name($this->value);
}
/**
* Returns the localized name based on the field's value.
* Example: "de_DE" returns "Deutsch".
2014-08-15 08:53:05 +02:00
*
* @return String
*/
public function getNativeName() {
$common_names = i18n::get_common_locales(true);
return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
}
}