Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / settings / setting / PhabricatorTranslationSetting.php
blob42657e396ca78ad4ff80e7b7cc8ba2b1dd093ffe
1 <?php
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() {
17 return 100;
20 public function getSettingDefaultValue() {
21 return 'en_US';
24 protected function getControlInstructions() {
25 return pht(
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();
55 unset($raw_scope);
57 if ($locale->isSillyLocale()) {
58 $groups['silly'][$code] = $name;
59 continue;
62 if ($locale->isTestLocale()) {
63 $groups['test'][$code] = $name;
64 continue;
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) {
79 $type = 'normal';
80 } else {
81 $type = 'limited';
84 $groups[$type][$code] = $name;
87 // Omit silly locales on serious business installs.
88 $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
89 if ($is_serious) {
90 unset($groups['silly']);
93 // Omit limited and test translations if Phabricator is not in developer
94 // mode.
95 $is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
96 if (!$is_dev) {
97 unset($groups['limited']);
98 unset($groups['test']);
101 $results = array();
102 foreach ($groups as $key => $group) {
103 $label = $group_labels[$key];
104 if (!$group) {
105 continue;
108 asort($group);
110 $results[] = array(
111 'label' => $label,
112 'options' => $group,
116 return $results;