mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-26 12:36:07 +02:00
API: Deprecate SS_Datetime. The DBField subclasses are have all been renamed to start with “DB” and be in the SilverStripe\Model\FieldType namespace. To keep DataObject definitions concise, the original short variations of their names are preserved as service definitions. Most of the field generation code doesn’t need to change, but where field classes are referenced directly, changes will be needed. SS_Datetime, which is commonly referenced outside the model system itself, has been preserved as a subclass of DBDatetime. This has been marked as deprecated and can be removed in SilverStripe 5. A few places that referred to $db and $casting values weren’t using the Injector to instantiate the relevant classes. This meant that the remapping we have created as part of moving classes into a namespace didn’t work.
69 lines
1.5 KiB
PHP
69 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Model\FieldType;
|
|
|
|
use i18n;
|
|
|
|
/**
|
|
* Locale database field, mainly used in {@link Translatable} extension.
|
|
*
|
|
* @todo Allowing showing locale values in different languages through Nice()
|
|
*
|
|
* @package framework
|
|
* @subpackage i18n
|
|
*/
|
|
class DBLocale extends DBVarchar {
|
|
|
|
public function __construct($name, $size = 16) {
|
|
parent::__construct($name, $size);
|
|
}
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
public function Nice($showNative=false) {
|
|
if ($showNative) {
|
|
return $this->getNativeName();
|
|
}
|
|
return $this->getShortName();
|
|
}
|
|
|
|
public function RFC1766() {
|
|
return i18n::convert_rfc1766($this->value);
|
|
}
|
|
|
|
/**
|
|
* Resolves the locale to a common english-language
|
|
* name through {@link i18n::get_common_locales()}.
|
|
*
|
|
* @return String
|
|
*/
|
|
public function getShortName() {
|
|
$common_names = i18n::get_common_locales();
|
|
return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
|
|
}
|
|
|
|
/**
|
|
* @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".
|
|
*
|
|
* @return String
|
|
*/
|
|
public function getNativeName() {
|
|
$common_names = i18n::get_common_locales(true);
|
|
return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
|
|
}
|
|
}
|
|
|