@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.

Send mail to targets in the user's translation

Summary: Ref T6367.

Test Plan:
- Added and executed unit tests.
- Sent mail to A (en_US) and B (en_A*).
- Got one mail in English and one mail in ENGLISH.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T6367

Differential Revision: https://secure.phabricator.com/D13142

+117 -7
+4
src/__phutil_library_map__.php
··· 1976 1976 'PhabricatorListFilterUIExample' => 'applications/uiexample/examples/PhabricatorListFilterUIExample.php', 1977 1977 'PhabricatorLocalDiskFileStorageEngine' => 'applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php', 1978 1978 'PhabricatorLocalTimeTestCase' => 'view/__tests__/PhabricatorLocalTimeTestCase.php', 1979 + 'PhabricatorLocaleScopeGuard' => 'infrastructure/internationalization/scope/PhabricatorLocaleScopeGuard.php', 1980 + 'PhabricatorLocaleScopeGuardTestCase' => 'infrastructure/internationalization/scope/__tests__/PhabricatorLocaleScopeGuardTestCase.php', 1979 1981 'PhabricatorLogTriggerAction' => 'infrastructure/daemon/workers/action/PhabricatorLogTriggerAction.php', 1980 1982 'PhabricatorLogoutController' => 'applications/auth/controller/PhabricatorLogoutController.php', 1981 1983 'PhabricatorLunarPhasePolicyRule' => 'applications/policy/rule/PhabricatorLunarPhasePolicyRule.php', ··· 5389 5391 'PhabricatorListFilterUIExample' => 'PhabricatorUIExample', 5390 5392 'PhabricatorLocalDiskFileStorageEngine' => 'PhabricatorFileStorageEngine', 5391 5393 'PhabricatorLocalTimeTestCase' => 'PhabricatorTestCase', 5394 + 'PhabricatorLocaleScopeGuard' => 'Phobject', 5395 + 'PhabricatorLocaleScopeGuardTestCase' => 'PhabricatorTestCase', 5392 5396 'PhabricatorLogTriggerAction' => 'PhabricatorTriggerAction', 5393 5397 'PhabricatorLogoutController' => 'PhabricatorAuthController', 5394 5398 'PhabricatorLunarPhasePolicyRule' => 'PhabricatorPolicyRule',
+1 -4
src/applications/base/controller/PhabricatorController.php
··· 114 114 $request->setUser($user); 115 115 } 116 116 117 - $locale_code = $user->getTranslation(); 118 - if ($locale_code) { 119 - PhabricatorEnv::setLocaleCode($locale_code); 120 - } 117 + PhabricatorEnv::setLocaleCode($user->getTranslation()); 121 118 122 119 $preferences = $user->loadPreferences(); 123 120 if (PhabricatorEnv::getEnvConfig('darkconsole.enabled')) {
+2 -1
src/applications/repository/worker/PhabricatorRepositoryPushMailWorker.php
··· 42 42 43 43 $task_data = $this->getTaskData(); 44 44 $viewer = $target->getViewer(); 45 - // TODO: Swap locale to viewer locale. 45 + 46 + $locale = PhabricatorEnv::beginScopedLocale($viewer->getTranslation()); 46 47 47 48 $logs = $event->getLogs(); 48 49
+6 -2
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 2139 2139 $mailed = array(); 2140 2140 foreach ($targets as $target) { 2141 2141 $original_actor = $this->getActor(); 2142 - $this->setActor($target->getViewer()); 2143 - // TODO: Swap locale to viewer locale. 2142 + 2143 + $viewer = $target->getViewer(); 2144 + $this->setActor($viewer); 2145 + $locale = PhabricatorEnv::beginScopedLocale($viewer->getTranslation()); 2144 2146 2145 2147 $caught = null; 2146 2148 try { ··· 2153 2155 } 2154 2156 2155 2157 $this->setActor($original_actor); 2158 + unset($locale); 2159 + 2156 2160 if ($caught) { 2157 2161 throw $ex; 2158 2162 }
+12
src/infrastructure/env/PhabricatorEnv.php
··· 129 129 self::setLocaleCode('en_US'); 130 130 } 131 131 132 + public static function beginScopedLocale($locale_code) { 133 + return new PhabricatorLocaleScopeGuard($locale_code); 134 + } 135 + 136 + public static function getLocaleCode() { 137 + return self::$localeCode; 138 + } 139 + 132 140 public static function setLocaleCode($locale_code) { 141 + if (!$locale_code) { 142 + return; 143 + } 144 + 133 145 if ($locale_code == self::$localeCode) { 134 146 return; 135 147 }
+54
src/infrastructure/internationalization/scope/PhabricatorLocaleScopeGuard.php
··· 1 + <?php 2 + 3 + /** 4 + * Change the effective locale for the lifetime of this guard. 5 + * 6 + * Use @{method:PhabricatorEnv::beginScopedLocale} to acquire a guard. 7 + * Guards are released when they exit scope. 8 + */ 9 + final class PhabricatorLocaleScopeGuard 10 + extends Phobject { 11 + 12 + private static $stack = array(); 13 + private $key; 14 + private $destroyed; 15 + 16 + public function __construct($code) { 17 + // If this is the first time we're building a guard, push the default 18 + // locale onto the bottom of the stack. We'll never remove it. 19 + if (empty(self::$stack)) { 20 + self::$stack[] = PhabricatorEnv::getLocaleCode(); 21 + } 22 + 23 + // If there's no locale, use the server default locale. 24 + if (!$code) { 25 + $code = self::$stack[0]; 26 + } 27 + 28 + // Push this new locale onto the stack and set it as the active locale. 29 + // We keep track of which key this guard owns, in case guards are destroyed 30 + // out-of-order. 31 + self::$stack[] = $code; 32 + $this->key = last_key(self::$stack); 33 + 34 + PhabricatorEnv::setLocaleCode($code); 35 + } 36 + 37 + public function __destruct() { 38 + if ($this->destroyed) { 39 + return; 40 + } 41 + $this->destroyed = true; 42 + 43 + // Remove this locale from the stack and set the new active locale. Usually, 44 + // we're the last item on the stack, so this shortens the stack by one item 45 + // and sets the locale underneath. However, it's possible that guards are 46 + // being destroyed out of order, so we might just be removing an item 47 + // somewhere in the middle of the stack. In this case, we won't actually 48 + // change the locale, just set it to its current value again. 49 + 50 + unset(self::$stack[$this->key]); 51 + PhabricatorEnv::setLocaleCode(end(self::$stack)); 52 + } 53 + 54 + }
+38
src/infrastructure/internationalization/scope/__tests__/PhabricatorLocaleScopeGuardTestCase.php
··· 1 + <?php 2 + 3 + final class PhabricatorLocaleScopeGuardTestCase 4 + extends PhabricatorTestCase { 5 + 6 + public function testLocaleScopeGuard() { 7 + $original = PhabricatorEnv::getLocaleCode(); 8 + 9 + // Set a guard; it should change the locale, then revert it when destroyed. 10 + $guard = PhabricatorEnv::beginScopedLocale('en_GB'); 11 + $this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode()); 12 + unset($guard); 13 + $this->assertEqual($original, PhabricatorEnv::getLocaleCode()); 14 + 15 + // Nest guards, then destroy them out of order. 16 + $guard1 = PhabricatorEnv::beginScopedLocale('en_GB'); 17 + $this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode()); 18 + $guard2 = PhabricatorEnv::beginScopedLocale('en_A*'); 19 + $this->assertEqual('en_A*', PhabricatorEnv::getLocaleCode()); 20 + unset($guard1); 21 + $this->assertEqual('en_A*', PhabricatorEnv::getLocaleCode()); 22 + unset($guard2); 23 + $this->assertEqual($original, PhabricatorEnv::getLocaleCode()); 24 + 25 + // If you push `null`, that should mean "the default locale", not 26 + // "the current locale". 27 + $guard3 = PhabricatorEnv::beginScopedLocale('en_GB'); 28 + $this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode()); 29 + $guard4 = PhabricatorEnv::beginScopedLocale(null); 30 + $this->assertEqual($original, PhabricatorEnv::getLocaleCode()); 31 + unset($guard4); 32 + $this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode()); 33 + unset($guard3); 34 + $this->assertEqual($original, PhabricatorEnv::getLocaleCode()); 35 + 36 + } 37 + 38 + }