Update Phabricator to work with more modular translations
Summary: Ref T7152. Ref T1139. This updates Phabricator so third-party libraries can translate their own stuff. Also: - Hide "All Caps" when not in development mode, since some users have found this a little confusing. - With other changes, adds a "Raw Strings" mode (development mode only). - Add an example silly translation to make sure the serious business flag works. - Add a basic British English translation. - Simplify handling of translation overrides. Test Plan: - Flipped serious business / development on and off and saw silly/development translations drop off. - Switched to "All Caps" and saw all caps. - Switched to Very English, Wow! - Switched to British english and saw "colour". Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T7152, T1139 Differential Revision: https://secure.phabricator.com/D11747
This commit is contained in:
@@ -96,13 +96,9 @@ abstract class PhabricatorController extends AphrontController {
|
||||
$request->setUser($user);
|
||||
}
|
||||
|
||||
$translation = $user->getTranslation();
|
||||
if ($translation &&
|
||||
$translation != PhabricatorEnv::getEnvConfig('translation.provider')) {
|
||||
$translation = newv($translation, array());
|
||||
PhutilTranslator::getInstance()
|
||||
->setLanguage($translation->getLanguage())
|
||||
->addTranslations($translation->getCleanTranslations());
|
||||
$locale_code = $user->getTranslation();
|
||||
if ($locale_code) {
|
||||
PhabricatorEnv::setLocaleCode($locale_code);
|
||||
}
|
||||
|
||||
$preferences = $user->loadPreferences();
|
||||
|
||||
@@ -203,6 +203,9 @@ final class PhabricatorExtraConfigSetupCheck extends PhabricatorSetupCheck {
|
||||
'the server as the user you want it to run under.'),
|
||||
'notification.debug' => pht(
|
||||
'Notifications no longer have a dedicated debugging mode.'),
|
||||
'translation.provider' => pht(
|
||||
'The translation implementation has changed and providers are no '.
|
||||
'longer used or supported.'),
|
||||
);
|
||||
|
||||
return $ancient_config;
|
||||
|
||||
@@ -21,19 +21,6 @@ final class PhabricatorTranslationsConfigOptions
|
||||
|
||||
public function getOptions() {
|
||||
return array(
|
||||
$this->newOption(
|
||||
'translation.provider',
|
||||
'class',
|
||||
'PhabricatorEnglishTranslation')
|
||||
->setBaseClass('PhabricatorTranslation')
|
||||
->setSummary(pht('Translation class that should be used for strings.'))
|
||||
->setDescription(
|
||||
pht(
|
||||
'This allows customizing texts used in Phabricator. The class '.
|
||||
'must extend PhabricatorTranslation.'))
|
||||
->addExample('PhabricatorEnglishTranslation', pht('Valid Setting')),
|
||||
// TODO: This should be dict<string,string> I think, but that doesn't
|
||||
// exist yet.
|
||||
$this->newOption('translation.override', 'wild', array())
|
||||
->setSummary(pht('Override translations.'))
|
||||
->setDescription(
|
||||
|
||||
@@ -190,19 +190,6 @@ final class PhabricatorUser
|
||||
return '@'.$this->getUsername();
|
||||
}
|
||||
|
||||
public function getTranslation() {
|
||||
try {
|
||||
if ($this->translation &&
|
||||
class_exists($this->translation) &&
|
||||
is_subclass_of($this->translation, 'PhabricatorTranslation')) {
|
||||
return $this->translation;
|
||||
}
|
||||
} catch (PhutilMissingSymbolException $ex) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function isLoggedIn() {
|
||||
return !($this->getPHID() === null);
|
||||
}
|
||||
|
||||
@@ -64,20 +64,28 @@ final class PhabricatorAccountSettingsPanel extends PhabricatorSettingsPanel {
|
||||
PhutilPerson::SEX_FEMALE => $label_her,
|
||||
);
|
||||
|
||||
$locales = PhutilLocale::loadAllLocales();
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
$is_dev = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
|
||||
|
||||
$translations = array();
|
||||
$symbols = id(new PhutilSymbolLoader())
|
||||
->setType('class')
|
||||
->setAncestorClass('PhabricatorTranslation')
|
||||
->setConcreteOnly(true)
|
||||
->selectAndLoadSymbols();
|
||||
foreach ($symbols as $symbol) {
|
||||
$class = $symbol['name'];
|
||||
$translations[$class] = newv($class, array())->getName();
|
||||
foreach ($locales as $locale) {
|
||||
if ($is_serious && $locale->isSillyLocale()) {
|
||||
// Omit silly locales on serious business installs.
|
||||
continue;
|
||||
}
|
||||
if (!$is_dev && $locale->isTestLocale()) {
|
||||
// Omit test locales on installs which aren't in development mode.
|
||||
continue;
|
||||
}
|
||||
$translations[$locale->getLocaleCode()] = $locale->getLocaleName();
|
||||
}
|
||||
|
||||
asort($translations);
|
||||
$default = PhabricatorEnv::newObjectFromConfig('translation.provider');
|
||||
// TODO: Implement "locale.default" and use it here.
|
||||
$default = 'en_US';
|
||||
$translations = array(
|
||||
'' => pht('Server Default (%s)', $default->getName()),
|
||||
'' => pht('Server Default: %s', $locales[$default]->getLocaleName()),
|
||||
) + $translations;
|
||||
|
||||
$form = new AphrontFormView();
|
||||
|
||||
Reference in New Issue
Block a user