protected function getSelectOptionGroups() { $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); $locales = PhutilLocale::loadAllLocales(); $group_labels = array('normal' => pht('Translations'), 'limited' => pht('Limited Translations'), 'silly' => pht('Silly Translations'), 'test' => pht('Developer/Test Translations')); $groups = array_fill_keys(array_keys($group_labels), array()); $translations = array(); foreach ($locales as $locale) { $code = $locale->getLocaleCode(); // Get the locale's localized name if it's available. For example, // "Deutsch" instead of "German". This helps users who do not speak the // current language to find the correct setting. $raw_scope = PhabricatorEnv::beginScopedLocale($code); $name = $locale->getLocaleName(); unset($raw_scope); if ($locale->isSillyLocale()) { if ($is_serious) { // Omit silly locales on serious business installs. continue; } $groups['silly'][$code] = $name; continue; } if ($locale->isTestLocale()) { $groups['test'][$code] = $name; continue; } $strings = PhutilTranslation::getTranslationMapForLocale($code); $size = count($strings); // If a translation is English, assume it can fall back to the default // strings and don't caveat its completeness. $is_english = substr($code, 0, 3) == 'en_'; // Arbitrarily pick some number of available strings to promote a // translation out of the "limited" group. The major goal is just to // keep locales with very few strings out of the main group, so users // aren't surprised if a locale has no upstream translations available. if ($size > 512 || $is_english) { $type = 'normal'; } else { $type = 'limited'; } $groups[$type][$code] = $name; } $results = array(); foreach ($groups as $key => $group) { $label = $group_labels[$key]; if (!$group) { continue; } asort($group); $results[] = array('label' => $label, 'options' => $group); } return $results; }
public static function setLocaleCode($locale_code) { if (!$locale_code) { return; } if ($locale_code == self::$localeCode) { return; } try { $locale = PhutilLocale::loadLocale($locale_code); $translations = PhutilTranslation::getTranslationMapForLocale($locale_code); $override = self::getEnvConfig('translation.override'); if (!is_array($override)) { $override = array(); } PhutilTranslator::getInstance()->setLocale($locale)->setTranslations($override + $translations); self::$localeCode = $locale_code; } catch (Exception $ex) { // Just ignore this; the user likely has an out-of-date locale code. } }
* - Next to 'arcanist/'. * - Anywhere in the normal PHP 'include_path'. * - Inside 'arcanist/externals/includes/'. * * When looking in these places, we expect to find a 'libphutil/' directory. */ function arcanist_adjust_php_include_path() { // The 'arcanist/' directory. $arcanist_dir = dirname(dirname(__FILE__)); // The parent directory of 'arcanist/'. $parent_dir = dirname($arcanist_dir); // The 'arcanist/externals/includes/' directory. $include_dir = implode(DIRECTORY_SEPARATOR, array($arcanist_dir, 'externals', 'includes')); $php_include_path = ini_get('include_path'); $php_include_path = implode(PATH_SEPARATOR, array($parent_dir, $php_include_path, $include_dir)); ini_set('include_path', $php_include_path); } arcanist_adjust_php_include_path(); if (getenv('ARC_PHUTIL_PATH')) { @(include_once getenv('ARC_PHUTIL_PATH') . '/scripts/__init_script__.php'); } else { @(include_once 'libphutil/scripts/__init_script__.php'); } if (!@constant('__LIBPHUTIL__')) { echo "ERROR: Unable to load libphutil. Put libphutil/ next to arcanist/, or " . "update your PHP 'include_path' to include the parent directory of " . "libphutil/, or symlink libphutil/ into arcanist/externals/includes/.\n"; exit(1); } phutil_load_library(dirname(dirname(__FILE__)) . '/src/'); PhutilTranslator::getInstance()->setLocale(PhutilLocale::loadLocale('en_US'))->setTranslations(PhutilTranslation::getTranslationMapForLocale('en_US'));