当前位置: 首页>>代码示例>>PHP>>正文


PHP i18n::get_common_locales方法代码示例

本文整理汇总了PHP中i18n::get_common_locales方法的典型用法代码示例。如果您正苦于以下问题:PHP i18n::get_common_locales方法的具体用法?PHP i18n::get_common_locales怎么用?PHP i18n::get_common_locales使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在i18n的用法示例。


在下文中一共展示了i18n::get_common_locales方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Create a new LanguageDropdownField
  * @param string $name
  * @param string $title
  * @param array $excludeLocales List of locales that won't be included
  * @param string $translatingClass Name of the class with translated instances where to look for used languages
  * @param string $list Indicates the source language list. Can be either Common-English, Common-Native, Locale-English, Locale-Native
  */
 function __construct($name, $title, $excludeLocales = array(), $translatingClass = 'SiteTree', $list = 'Common-English', $instance = null)
 {
     $usedLocalesWithTitle = Translatable::get_existing_content_languages($translatingClass);
     $usedLocalesWithTitle = array_diff_key($usedLocalesWithTitle, $excludeLocales);
     if ('Common-English' == $list) {
         $allLocalesWithTitle = i18n::get_common_languages();
     } else {
         if ('Common-Native' == $list) {
             $allLocalesWithTitle = i18n::get_common_languages(true);
         } else {
             if ('Locale-English' == $list) {
                 $allLocalesWithTitle = i18n::get_common_locales();
             } else {
                 if ('Locale-Native' == $list) {
                     $allLocalesWithTitle = i18n::get_common_locales(true);
                 } else {
                     $allLocalesWithTitle = i18n::get_locale_list();
                 }
             }
         }
     }
     if (isset($allLocales[Translatable::default_locale()])) {
         unset($allLocales[Translatable::default_locale()]);
     }
     // Limit to allowed locales if defined
     // Check for canTranslate() if an $instance is given
     $allowedLocales = Translatable::get_allowed_locales();
     foreach ($allLocalesWithTitle as $locale => $localeTitle) {
         if ($allowedLocales && !in_array($locale, $allowedLocales) || $excludeLocales && in_array($locale, $excludeLocales) || $usedLocalesWithTitle && array_key_exists($locale, $usedLocalesWithTitle)) {
             unset($allLocalesWithTitle[$locale]);
         }
     }
     // instance specific permissions
     foreach ($allLocalesWithTitle as $locale => $localeTitle) {
         if ($instance && !$instance->canTranslate(null, $locale)) {
             unset($allLocalesWithTitle[$locale]);
         }
     }
     foreach ($usedLocalesWithTitle as $locale => $localeTitle) {
         if ($instance && !$instance->canTranslate(null, $locale)) {
             unset($usedLocalesWithTitle[$locale]);
         }
     }
     // Sort by title (array value)
     asort($allLocalesWithTitle);
     if (count($usedLocalesWithTitle)) {
         asort($usedLocalesWithTitle);
         $source = array(_t('Form.LANGAVAIL', "Available languages") => $usedLocalesWithTitle, _t('Form.LANGAOTHER', "Other languages") => $allLocalesWithTitle);
     } else {
         $source = $allLocalesWithTitle;
     }
     parent::__construct($name, $title, $source);
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:61,代码来源:LanguageDropdownField.php

示例2: getNativeName

 /**
  * 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;
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:11,代码来源:DBLocale.php

示例3: locale_native_name

 /**
  *
  * Fetch a native language string from the `i18n` class via a passed locale
  * in the format "XX_xx". In the event a match cannot be found in any framework
  * resource, an empty string is returned.
  *
  * @param string $locale e.g. "pt_BR"
  * @return string The native language string for that locale e.g. "português (Brazil)"
  */
 public static function locale_native_name($locale)
 {
     // Attempts to fetch the native language string via the `i18n::$common_languages` array
     if ($native = i18n::get_language_name(i18n::get_lang_from_locale($locale), true)) {
         return $native;
     }
     // Attempts to fetch the native language string via the `i18n::$common_locales` array
     $commonLocales = i18n::get_common_locales(true);
     if (!empty($commonLocales[$locale])) {
         return $commonLocales[$locale];
     }
     // Nothing else to go on, so return an empty string for a consistent API
     return '';
 }
开发者ID:helpfulrobot,项目名称:tractorcow-silverstripe-fluent,代码行数:23,代码来源:Fluent.php

示例4: getAllowedLocalesForMember

 /**
  * Gets all locales that a member can access
  * as defined by {@link $allowed_locales}
  * and {@link canTranslate()}.
  * If {@link $allowed_locales} is not set and
  * the user has the `TRANSLATE_ALL` permission,
  * the method will return all available locales in the system.
  * 
  * @param Member $member
  * @return array Map of locales
  */
 function getAllowedLocalesForMember($member)
 {
     $locales = self::get_allowed_locales();
     if (!$locales) {
         $locales = i18n::get_common_locales();
     }
     if ($locales) {
         foreach ($locales as $k => $locale) {
             if (!$this->canTranslate($member, $locale)) {
                 unset($locales[$k]);
             }
         }
     }
     return $locales;
 }
开发者ID:eLBirador,项目名称:AllAboutCity,代码行数:26,代码来源:Translatable.php

示例5: getCMSFields

 /**
  * Show the configuration fields for each subsite
  */
 function getCMSFields()
 {
     $domainTable = new TableField("Domains", "SubsiteDomain", array("Domain" => "Domain (use * as a wildcard)", "IsPrimary" => "Primary domain?"), array("Domain" => "TextField", "IsPrimary" => "CheckboxField"), "SubsiteID", $this->ID);
     $languageSelector = new DropdownField('Language', 'Language', i18n::get_common_locales());
     $fields = new FieldSet(new TabSet('Root', new Tab('Configuration', new HeaderField($this->getClassName() . ' configuration', 2), new TextField('Title', 'Name of subsite:', $this->Title), new HeaderField("Domains for this subsite"), $domainTable, $languageSelector, new CheckboxField('DefaultSite', 'Default site', $this->DefaultSite), new CheckboxField('IsPublic', 'Enable public access', $this->IsPublic), new DropdownField('Theme', 'Theme', $this->allowedThemes(), $this->Theme))), new HiddenField('ID', '', $this->ID), new HiddenField('IsSubsite', '', 1));
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
开发者ID:hafriedlander,项目名称:silverstripe-config-experiment,代码行数:11,代码来源:Subsite.php

示例6: getCMSFields

 /**
  * Show the configuration fields for each subsite
  * 
  * @return FieldList
  */
 public function getCMSFields()
 {
     if ($this->ID != 0) {
         $domainTable = new GridField("Domains", _t('Subsite.DomainsListTitle', "Domains"), $this->Domains(), GridFieldConfig_RecordEditor::create(10));
     } else {
         $domainTable = new LiteralField('Domains', '<p>' . _t('Subsite.DOMAINSAVEFIRST', 'You can only add domains after saving for the first time') . '</p>');
     }
     $languageSelector = new DropdownField('Language', $this->fieldLabel('Language'), i18n::get_common_locales());
     $pageTypeMap = array();
     $pageTypes = SiteTree::page_type_classes();
     foreach ($pageTypes as $pageType) {
         $pageTypeMap[$pageType] = singleton($pageType)->i18n_singular_name();
     }
     asort($pageTypeMap);
     $fields = new FieldList($subsiteTabs = new TabSet('Root', new Tab('Configuration', _t('Subsite.TabTitleConfig', 'Configuration'), new HeaderField($this->getClassName() . ' configuration', 2), new TextField('Title', $this->fieldLabel('Title'), $this->Title), new HeaderField(_t('Subsite.DomainsHeadline', "Domains for this subsite")), $domainTable, $languageSelector, new CheckboxField('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite), new CheckboxField('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic), new DropdownField('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme), new LiteralField('PageTypeBlacklistToggle', sprintf('<div class="field"><a href="#" id="PageTypeBlacklistToggle">%s</a></div>', _t('Subsite.PageTypeBlacklistField', 'Disallow page types?'))), new CheckboxSetField('PageTypeBlacklist', false, $pageTypeMap))), new HiddenField('ID', '', $this->ID), new HiddenField('IsSubsite', '', 1));
     $subsiteTabs->addExtraClass('subsite-model');
     $this->extend('updateCMSFields', $fields);
     return $fields;
 }
开发者ID:hamaka,项目名称:silverstripe-subsites,代码行数:24,代码来源:Subsite.php

示例7: getShortName

 function getShortName()
 {
     $common_names = i18n::get_common_locales();
     return isset($common_names[$this->value]) ? $common_names[$this->value] : false;
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:5,代码来源:DBLocale.php

示例8: getDisplayLanguage

 /**
  * Returns the language name
  *
  * @param string $locale    Locale to get name for
  * @param string $in_locale Locale to display name in (when PHP intl is not installed, this is the indicator for native displaying)
  * 
  * @return string
  */
 public static function getDisplayLanguage($locale, $in_locale)
 {
     if (class_exists('Locale')) {
         $languageName = Locale::getDisplayLanguage($locale, $in_locale);
     } else {
         $native = false;
         if ($locale == $in_locale) {
             $native = true;
         }
         $languageName = i18n::get_language_name(substr($locale, 0, strpos($locale, '_')), $native);
         if (empty($languageName)) {
             $common_locales = i18n::get_common_locales($native);
             $all_locales = (array) Config::inst()->get('i18n', 'all_locales');
             if (array_key_exists($locale, $common_locales)) {
                 $languageName = $common_locales[$locale];
             } elseif (array_key_exists($locale, $all_locales)) {
                 $languageName = $all_locales[$locale];
             }
         }
     }
     return $languageName;
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:30,代码来源:SilvercartLanguageHelper.php


注:本文中的i18n::get_common_locales方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。