@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Support setting a locale for `bin/*` command-line scripts

Summary:
Fixes T16388.

Depends on D26580

Test Plan:
- Install downstream translations extension
- Set a `locale.command` locale, either via the web UI or `bin/config set locale.command fr_FR`
- Run a `bin/*` command and see its output in French
- Set `locale.command` to something bogus.
- Run a `bin/*` command and see it doesn't crash (and instead uses English), allowing you to fix the problem.
- Run a `bin/*` command with a `--locale` arg and see the locale in the command line override the locale as configured.

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: avivey, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T16388

Differential Revision: https://we.phorge.it/D26582

Pppery c8c974f1 dded7282

+27 -4
+10
src/applications/config/option/PhabricatorTranslationsConfigOptions.php
··· 32 32 ->addExample( 33 33 '{"some string": "my alternative"}', 34 34 pht('Valid Setting')), 35 + // Ideally this would be an enum but it can't be because of bootstrapping 36 + // problems - this code runs before extensions load, so if we load 37 + // locales now to populate the enum then locales defined by extensions 38 + // wouldn't load. 39 + $this->newOption('locale.command', 'string', 'en_US') 40 + ->setSummary(pht('Locale code of command-line locale.')) 41 + ->setDescription(pht( 42 + 'What locale to use for command-line scripts that '. 43 + 'don\'t specify a `%s` argument.', 44 + '--locale')), 35 45 ); 36 46 } 37 47
+17 -4
src/infrastructure/env/PhabricatorEnv.php
··· 69 69 */ 70 70 public static function initializeWebEnvironment() { 71 71 self::initializeCommonEnvironment(false, false); 72 + 73 + // Set up en_US locale for now so that, for instance, if you haven't 74 + // set up your database at all it says "Run this command" rather than 75 + // "Run these 1 command(s)" 76 + // If there aren't any setup problems, then this will get overwritten with 77 + // the logged-in user's locale or the locale specified in global default 78 + // settings by PhabricatorAuthSessionEngine::willServeRequestForUser 79 + // which is called from PhabricatorController:willBeginExecution 80 + self::setLocaleCode('en_US'); 81 + 72 82 } 73 83 74 84 public static function initializeScriptEnvironment( 75 85 $config_optional, 76 86 $no_extensions) { 77 87 self::initializeCommonEnvironment($config_optional, $no_extensions); 88 + 89 + // Set the default locale for command-line scripts 90 + self::setLocaleCode(self::getEnvConfig('locale.command')); 91 + 92 + // If a script has a --locale argument then go through our system for 93 + // setting locales 94 + PhutilArgumentParser::setLocaleCallback(array(__CLASS__, 'setLocaleCode')); 78 95 79 96 // NOTE: This is dangerous in general, but we know we're in a script context 80 97 // and are not vulnerable to CSRF. ··· 135 152 } 136 153 137 154 PhabricatorEventEngine::initialize(); 138 - 139 - // TODO: Add a "locale.default" config option once we have some reasonable 140 - // defaults which aren't silly nonsense. 141 - self::setLocaleCode('en_US'); 142 155 143 156 // Load the preamble utility library if we haven't already. On web 144 157 // requests this loaded earlier, but we want to load it for non-web