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


PHP i18n::get_locale_list方法代码示例

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


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

示例1: __construct

 /**
  * Create a new LanguageDropdownField
  * @param string $name
  * @param string $title
  * @param array $dontInclude list of languages 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
  */
 function __construct($name, $title, $dontInclude = array(), $translatingClass = 'SiteTree', $list = 'Common-English')
 {
     $usedlangs = array_diff(i18n::get_existing_content_languages($translatingClass), $dontInclude);
     // we accept in dontInclude both language codes and names, so another diff is required
     $usedlangs = array_diff($usedlangs, array_flip($dontInclude));
     if (isset($usedlangs[Translatable::default_lang()])) {
         unset($usedlangs[Translatable::default_lang()]);
     }
     if ('Common-English' == $list) {
         $languageList = i18n::get_common_languages();
     } else {
         if ('Common-Native' == $list) {
             $languageList = i18n::get_common_languages(true);
         } else {
             $languageList = i18n::get_locale_list();
         }
     }
     $alllangs = array_diff($languageList, (array) $usedlangs, $dontInclude);
     $alllangs = array_flip(array_diff(array_flip($alllangs), $dontInclude));
     if (isset($alllangs[Translatable::default_lang()])) {
         unset($alllangs[Translatable::default_lang()]);
     }
     asort($alllangs);
     if (count($usedlangs)) {
         asort($usedlangs);
         $labelAvail = _t('Form.LANGAVAIL', "Available languages");
         $labelOther = _t('Form.LANGAOTHER', "Other languages");
         parent::__construct($name, $title, array($labelAvail => $usedlangs, $labelOther => $alllangs), reset($usedlangs));
     } else {
         parent::__construct($name, $title, $alllangs);
     }
 }
开发者ID:ramziammar,项目名称:websites,代码行数:40,代码来源:LanguageDropdownField.php

示例2: __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

示例3: set_default_locale

 /**
  * Set default language. Please set this value *before* creating
  * any database records (like pages), as this locale will be attached
  * to all new records.
  * 
  * @param $locale String
  */
 static function set_default_locale($locale)
 {
     if ($locale && !i18n::validate_locale($locale)) {
         throw new InvalidArgumentException(sprintf('Invalid locale "%s"', $locale));
     }
     $localeList = i18n::get_locale_list();
     if (isset($localeList[$locale])) {
         self::$default_locale = $locale;
     } else {
         user_error("Translatable::set_default_locale(): '{$locale}' is not a valid locale.", E_USER_WARNING);
     }
 }
开发者ID:eLBirador,项目名称:AllAboutCity,代码行数:19,代码来源:Translatable.php

示例4: set_default_locale

 /**
  * Set default language. Please set this value *before* creating
  * any database records (like pages), as this locale will be attached
  * to all new records.
  * 
  * @param $locale String
  */
 static function set_default_locale($locale)
 {
     $localeList = i18n::get_locale_list();
     if (isset($localeList[$locale])) {
         self::$default_locale = $locale;
     } else {
         user_error("Translatable::set_default_locale(): '{$locale}' is not a valid locale.", E_USER_WARNING);
     }
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:16,代码来源:Translatable.php

示例5: translate

 /**
  */
 function translate($data, $form)
 {
     increase_time_limit_to(600);
     // Simple validation
     if (!isset($data['From']) || !$data['From']) {
         echo "Specify origin language.";
         exit;
     }
     if (!isset($data['To']) || !$data['To']) {
         echo "Specify destination language.";
         exit;
     }
     $data['From'] = i18n::get_locale_from_lang($data['From']);
     $data['To'] = i18n::get_locale_from_lang($data['To']);
     $locales = array_keys(i18n::get_locale_list());
     if (!in_array($data['From'], $locales)) {
         echo "Origin language invalid.";
         exit;
     }
     if (!in_array($data['To'], $locales)) {
         echo "Destination language invalid.";
         exit;
     }
     if ($data['From'] == $data['To']) {
         echo "Origin and destination languages are the same.";
         exit;
     }
     $mangle = false;
     if (isset($data['Mangle']) && $data['Mangle']) {
         $mangle = true;
     }
     // We want to work off Draft, because that's what's visible in the CMS.
     Versioned::reading_stage('Stage');
     Translatable::set_current_locale($data['From']);
     $pages = SiteTree::get();
     // Remove the target locale's site.
     SiteTree::get()->filter('Locale', $data['To'])->removeAll();
     foreach ($pages as $page) {
         echo "Now processing {$page->ID}<br/>\n";
         // Start from the highest parent for each page - otherwise the parents are not translated properly.
         $stack = array();
         $parent = $page;
         while ($parent && $parent->ID) {
             array_unshift($stack, $parent);
             $parent = $parent->Parent();
         }
         // We will hit the same pages multiple times, but this is an easiest way to do it and it's just a tool.
         foreach ($stack as $stackPage) {
             $translation = $stackPage->getTranslation($data['To']);
             if ($translation && $translation->ID) {
                 // Skip pages that have already been translated.
                 echo "{$stackPage->ID}: exists, skipping.<br/>\n";
             } else {
                 $translation = $stackPage->createTranslation($data['To']);
                 if ($mangle) {
                     $this->fakeTranslation($translation);
                 }
                 $translation->write();
                 echo "{$stackPage->ID}: translated.<br/>\n";
             }
         }
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-testdata,代码行数:65,代码来源:EntireSiteTranslator.php

示例6: createMissingLocales

 /**
  * Creates missing locale files for all modules.
  *
  * @return void
  *
  * @author Sascha Koehler <skoehler@pixeltricks.de>
  * @since 16.05.2012
  */
 public static function createMissingLocales()
 {
     global $lang;
     $base = Director::baseFolder();
     $topLevel = scandir($base);
     $template = file_get_contents($base . '/silvercart/code_templates/locale/SilvercartLocaleTemplate.php');
     $locales = i18n::get_locale_list();
     foreach ($locales as $locale => $localeName) {
         if ($locale == 'en_US') {
             continue;
         }
         $moduleIncludeStr = array();
         foreach ($topLevel as $module) {
             if ($module[0] == '.' || $module == 'silvercart-cache') {
                 continue;
             }
             $localeFileName = "{$base}/silvercart-cache/lang/{$locale}.php";
             if (is_dir("{$base}/{$module}") && file_exists("{$base}/{$module}/_config.php") && file_exists("{$base}/{$module}/lang/en_US.php")) {
                 $moduleIncludeStr[] = "i18n::include_locale_file('" . $module . "', 'en_US');";
             }
         }
         $localeContent = str_replace(array('__MODULE_INCLUDES__', '__LOCALE__'), array(implode(PHP_EOL, $moduleIncludeStr), $locale), $template);
         file_put_contents($localeFileName, $localeContent);
     }
 }
开发者ID:silvercart,项目名称:silvercart,代码行数:33,代码来源:SilvercartLanguageHelper.php


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