Version: current

     1 <?php
     2 /**
     3  * Locale database field, mainly used in {@link Translatable} extension.
     4  *
     5  * @todo Allowing showing locale values in different languages through Nice()
     6  *
     7  * @package sapphire
     8  * @subpackage i18n
     9  */
    10 class DBLocale extends Varchar {
    11
    12     function __construct($name, $size = 16) {
    13         parent::__construct($name, $size);
    14     }
    15
    16     /**
    17      * See {@link getShortName()} and {@link getNativeName()}.
    18      *
    19      * @param Boolean $showNative Show a localized version of the name instead, based on the
    20      *  field's locale value.
    21      * @return String
    22      */
    23     function Nice($showNative=false) {
    24         if ($showNative) {
    25             return $this->getNativeName();
    26         }
    27         return $this->getShortName();
    28     }
    29
    30     function RFC1766() {
    31         return i18n::convert_rfc1766($this->value);
    32     }
    33
    34     /**
    35      * Resolves the locale to a common english-language
    36      * name through {@link i18n::get_common_locales()}.
    37      *
    38      * @return String
    39      */
    40     function getShortName() {
    41         $common_names = i18n::get_common_locales();
    42         return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
    43     }
    44
    45     /**
    46      * @return String
    47      */
    48     function getLongName() {
    49         return i18n::get_locale_name($this->value);
    50     }
    51
    52     /**
    53      * Returns the localized name based on the field's value.
    54      * Example: "de_DE" returns "Deutsch".
    55      *
    56      * @return String
    57      */
    58     function getNativeName() {
    59         $common_names = i18n::get_common_locales(true);
    60         return (isset($common_names[$this->value])) ? $common_names[$this->value] : false;
    61     }
    62 }
    63 ?>
    64

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -