diff --git a/src/applications/config/option/PhabricatorTranslationsConfigOptions.php b/src/applications/config/option/PhabricatorTranslationsConfigOptions.php index c82e7901bc..e4b624c385 100644 --- a/src/applications/config/option/PhabricatorTranslationsConfigOptions.php +++ b/src/applications/config/option/PhabricatorTranslationsConfigOptions.php @@ -32,6 +32,16 @@ final class PhabricatorTranslationsConfigOptions ->addExample( '{"some string": "my alternative"}', pht('Valid Setting')), + // Ideally this would be an enum but it can't be because of bootstrapping + // problems - this code runs before extensions load, so if we load + // locales now to populate the enum then locales defined by extensions + // wouldn't load. + $this->newOption('locale.command', 'string', 'en_US') + ->setSummary(pht('Locale code of command-line locale.')) + ->setDescription(pht( + 'What locale to use for command-line scripts that '. + 'don\'t specify a `%s` argument.', + '--locale')), ); } diff --git a/src/infrastructure/env/PhabricatorEnv.php b/src/infrastructure/env/PhabricatorEnv.php index 04f6b632e6..4436be2100 100644 --- a/src/infrastructure/env/PhabricatorEnv.php +++ b/src/infrastructure/env/PhabricatorEnv.php @@ -69,6 +69,16 @@ final class PhabricatorEnv extends Phobject { */ public static function initializeWebEnvironment() { self::initializeCommonEnvironment(false, false); + + // Set up en_US locale for now so that, for instance, if you haven't + // set up your database at all it says "Run this command" rather than + // "Run these 1 command(s)" + // If there aren't any setup problems, then this will get overwritten with + // the logged-in user's locale or the locale specified in global default + // settings by PhabricatorAuthSessionEngine::willServeRequestForUser + // which is called from PhabricatorController:willBeginExecution + self::setLocaleCode('en_US'); + } public static function initializeScriptEnvironment( @@ -76,6 +86,13 @@ final class PhabricatorEnv extends Phobject { $no_extensions) { self::initializeCommonEnvironment($config_optional, $no_extensions); + // Set the default locale for command-line scripts + self::setLocaleCode(self::getEnvConfig('locale.command')); + + // If a script has a --locale argument then go through our system for + // setting locales + PhutilArgumentParser::setLocaleCallback(array(__CLASS__, 'setLocaleCode')); + // NOTE: This is dangerous in general, but we know we're in a script context // and are not vulnerable to CSRF. AphrontWriteGuard::allowDangerousUnguardedWrites(true); @@ -136,10 +153,6 @@ final class PhabricatorEnv extends Phobject { PhabricatorEventEngine::initialize(); - // TODO: Add a "locale.default" config option once we have some reasonable - // defaults which aren't silly nonsense. - self::setLocaleCode('en_US'); - // Load the preamble utility library if we haven't already. On web // requests this loaded earlier, but we want to load it for non-web // requests so that unit tests can call these functions.