3 final class PhabricatorTranslationSetting
4 extends PhabricatorOptionGroupSetting
{
6 const SETTINGKEY
= 'translation';
8 public function getSettingName() {
9 return pht('Translation');
12 public function getSettingPanelKey() {
13 return PhabricatorLanguageSettingsPanel
::PANELKEY
;
16 protected function getSettingOrder() {
20 public function getSettingDefaultValue() {
24 protected function getControlInstructions() {
26 'Choose which language you would like the UI to use.');
29 public function assertValidValue($value) {
30 $locales = PhutilLocale
::loadAllLocales();
31 return isset($locales[$value]);
34 protected function getSelectOptionGroups() {
35 $locales = PhutilLocale
::loadAllLocales();
37 $group_labels = array(
38 'normal' => pht('Translations'),
39 'limited' => pht('Limited Translations'),
40 'silly' => pht('Silly Translations'),
41 'test' => pht('Developer/Test Translations'),
44 $groups = array_fill_keys(array_keys($group_labels), array());
46 $translations = array();
47 foreach ($locales as $locale) {
48 $code = $locale->getLocaleCode();
50 // Get the locale's localized name if it's available. For example,
51 // "Deutsch" instead of "German". This helps users who do not speak the
52 // current language to find the correct setting.
53 $raw_scope = PhabricatorEnv
::beginScopedLocale($code);
54 $name = $locale->getLocaleName();
57 if ($locale->isSillyLocale()) {
58 $groups['silly'][$code] = $name;
62 if ($locale->isTestLocale()) {
63 $groups['test'][$code] = $name;
67 $strings = PhutilTranslation
::getTranslationMapForLocale($code);
68 $size = count($strings);
70 // If a translation is English, assume it can fall back to the default
71 // strings and don't caveat its completeness.
72 $is_english = (substr($code, 0, 3) == 'en_');
74 // Arbitrarily pick some number of available strings to promote a
75 // translation out of the "limited" group. The major goal is just to
76 // keep locales with very few strings out of the main group, so users
77 // aren't surprised if a locale has no upstream translations available.
78 if ($size > 512 ||
$is_english) {
84 $groups[$type][$code] = $name;
87 // Omit silly locales on serious business installs.
88 $is_serious = PhabricatorEnv
::getEnvConfig('phabricator.serious-business');
90 unset($groups['silly']);
93 // Omit limited and test translations if Phabricator is not in developer
95 $is_dev = PhabricatorEnv
::getEnvConfig('phabricator.developer-mode');
97 unset($groups['limited']);
98 unset($groups['test']);
102 foreach ($groups as $key => $group) {
103 $label = $group_labels[$key];