mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-18 21:02:41 +01:00
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
This commit is contained in:
parent
6db97bde12
commit
069e60d2ff
7 changed files with 117 additions and 7 deletions
|
@ -1976,6 +1976,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorListFilterUIExample' => 'applications/uiexample/examples/PhabricatorListFilterUIExample.php',
|
'PhabricatorListFilterUIExample' => 'applications/uiexample/examples/PhabricatorListFilterUIExample.php',
|
||||||
'PhabricatorLocalDiskFileStorageEngine' => 'applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php',
|
'PhabricatorLocalDiskFileStorageEngine' => 'applications/files/engine/PhabricatorLocalDiskFileStorageEngine.php',
|
||||||
'PhabricatorLocalTimeTestCase' => 'view/__tests__/PhabricatorLocalTimeTestCase.php',
|
'PhabricatorLocalTimeTestCase' => 'view/__tests__/PhabricatorLocalTimeTestCase.php',
|
||||||
|
'PhabricatorLocaleScopeGuard' => 'infrastructure/internationalization/scope/PhabricatorLocaleScopeGuard.php',
|
||||||
|
'PhabricatorLocaleScopeGuardTestCase' => 'infrastructure/internationalization/scope/__tests__/PhabricatorLocaleScopeGuardTestCase.php',
|
||||||
'PhabricatorLogTriggerAction' => 'infrastructure/daemon/workers/action/PhabricatorLogTriggerAction.php',
|
'PhabricatorLogTriggerAction' => 'infrastructure/daemon/workers/action/PhabricatorLogTriggerAction.php',
|
||||||
'PhabricatorLogoutController' => 'applications/auth/controller/PhabricatorLogoutController.php',
|
'PhabricatorLogoutController' => 'applications/auth/controller/PhabricatorLogoutController.php',
|
||||||
'PhabricatorLunarPhasePolicyRule' => 'applications/policy/rule/PhabricatorLunarPhasePolicyRule.php',
|
'PhabricatorLunarPhasePolicyRule' => 'applications/policy/rule/PhabricatorLunarPhasePolicyRule.php',
|
||||||
|
@ -5389,6 +5391,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorListFilterUIExample' => 'PhabricatorUIExample',
|
'PhabricatorListFilterUIExample' => 'PhabricatorUIExample',
|
||||||
'PhabricatorLocalDiskFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
'PhabricatorLocalDiskFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
||||||
'PhabricatorLocalTimeTestCase' => 'PhabricatorTestCase',
|
'PhabricatorLocalTimeTestCase' => 'PhabricatorTestCase',
|
||||||
|
'PhabricatorLocaleScopeGuard' => 'Phobject',
|
||||||
|
'PhabricatorLocaleScopeGuardTestCase' => 'PhabricatorTestCase',
|
||||||
'PhabricatorLogTriggerAction' => 'PhabricatorTriggerAction',
|
'PhabricatorLogTriggerAction' => 'PhabricatorTriggerAction',
|
||||||
'PhabricatorLogoutController' => 'PhabricatorAuthController',
|
'PhabricatorLogoutController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorLunarPhasePolicyRule' => 'PhabricatorPolicyRule',
|
'PhabricatorLunarPhasePolicyRule' => 'PhabricatorPolicyRule',
|
||||||
|
|
|
@ -114,10 +114,7 @@ abstract class PhabricatorController extends AphrontController {
|
||||||
$request->setUser($user);
|
$request->setUser($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
$locale_code = $user->getTranslation();
|
PhabricatorEnv::setLocaleCode($user->getTranslation());
|
||||||
if ($locale_code) {
|
|
||||||
PhabricatorEnv::setLocaleCode($locale_code);
|
|
||||||
}
|
|
||||||
|
|
||||||
$preferences = $user->loadPreferences();
|
$preferences = $user->loadPreferences();
|
||||||
if (PhabricatorEnv::getEnvConfig('darkconsole.enabled')) {
|
if (PhabricatorEnv::getEnvConfig('darkconsole.enabled')) {
|
||||||
|
|
|
@ -42,7 +42,8 @@ final class PhabricatorRepositoryPushMailWorker
|
||||||
|
|
||||||
$task_data = $this->getTaskData();
|
$task_data = $this->getTaskData();
|
||||||
$viewer = $target->getViewer();
|
$viewer = $target->getViewer();
|
||||||
// TODO: Swap locale to viewer locale.
|
|
||||||
|
$locale = PhabricatorEnv::beginScopedLocale($viewer->getTranslation());
|
||||||
|
|
||||||
$logs = $event->getLogs();
|
$logs = $event->getLogs();
|
||||||
|
|
||||||
|
|
|
@ -2139,8 +2139,10 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
$mailed = array();
|
$mailed = array();
|
||||||
foreach ($targets as $target) {
|
foreach ($targets as $target) {
|
||||||
$original_actor = $this->getActor();
|
$original_actor = $this->getActor();
|
||||||
$this->setActor($target->getViewer());
|
|
||||||
// TODO: Swap locale to viewer locale.
|
$viewer = $target->getViewer();
|
||||||
|
$this->setActor($viewer);
|
||||||
|
$locale = PhabricatorEnv::beginScopedLocale($viewer->getTranslation());
|
||||||
|
|
||||||
$caught = null;
|
$caught = null;
|
||||||
try {
|
try {
|
||||||
|
@ -2153,6 +2155,8 @@ abstract class PhabricatorApplicationTransactionEditor
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setActor($original_actor);
|
$this->setActor($original_actor);
|
||||||
|
unset($locale);
|
||||||
|
|
||||||
if ($caught) {
|
if ($caught) {
|
||||||
throw $ex;
|
throw $ex;
|
||||||
}
|
}
|
||||||
|
|
12
src/infrastructure/env/PhabricatorEnv.php
vendored
12
src/infrastructure/env/PhabricatorEnv.php
vendored
|
@ -129,7 +129,19 @@ final class PhabricatorEnv {
|
||||||
self::setLocaleCode('en_US');
|
self::setLocaleCode('en_US');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function beginScopedLocale($locale_code) {
|
||||||
|
return new PhabricatorLocaleScopeGuard($locale_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getLocaleCode() {
|
||||||
|
return self::$localeCode;
|
||||||
|
}
|
||||||
|
|
||||||
public static function setLocaleCode($locale_code) {
|
public static function setLocaleCode($locale_code) {
|
||||||
|
if (!$locale_code) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($locale_code == self::$localeCode) {
|
if ($locale_code == self::$localeCode) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the effective locale for the lifetime of this guard.
|
||||||
|
*
|
||||||
|
* Use @{method:PhabricatorEnv::beginScopedLocale} to acquire a guard.
|
||||||
|
* Guards are released when they exit scope.
|
||||||
|
*/
|
||||||
|
final class PhabricatorLocaleScopeGuard
|
||||||
|
extends Phobject {
|
||||||
|
|
||||||
|
private static $stack = array();
|
||||||
|
private $key;
|
||||||
|
private $destroyed;
|
||||||
|
|
||||||
|
public function __construct($code) {
|
||||||
|
// If this is the first time we're building a guard, push the default
|
||||||
|
// locale onto the bottom of the stack. We'll never remove it.
|
||||||
|
if (empty(self::$stack)) {
|
||||||
|
self::$stack[] = PhabricatorEnv::getLocaleCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there's no locale, use the server default locale.
|
||||||
|
if (!$code) {
|
||||||
|
$code = self::$stack[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push this new locale onto the stack and set it as the active locale.
|
||||||
|
// We keep track of which key this guard owns, in case guards are destroyed
|
||||||
|
// out-of-order.
|
||||||
|
self::$stack[] = $code;
|
||||||
|
$this->key = last_key(self::$stack);
|
||||||
|
|
||||||
|
PhabricatorEnv::setLocaleCode($code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __destruct() {
|
||||||
|
if ($this->destroyed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->destroyed = true;
|
||||||
|
|
||||||
|
// Remove this locale from the stack and set the new active locale. Usually,
|
||||||
|
// we're the last item on the stack, so this shortens the stack by one item
|
||||||
|
// and sets the locale underneath. However, it's possible that guards are
|
||||||
|
// being destroyed out of order, so we might just be removing an item
|
||||||
|
// somewhere in the middle of the stack. In this case, we won't actually
|
||||||
|
// change the locale, just set it to its current value again.
|
||||||
|
|
||||||
|
unset(self::$stack[$this->key]);
|
||||||
|
PhabricatorEnv::setLocaleCode(end(self::$stack));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorLocaleScopeGuardTestCase
|
||||||
|
extends PhabricatorTestCase {
|
||||||
|
|
||||||
|
public function testLocaleScopeGuard() {
|
||||||
|
$original = PhabricatorEnv::getLocaleCode();
|
||||||
|
|
||||||
|
// Set a guard; it should change the locale, then revert it when destroyed.
|
||||||
|
$guard = PhabricatorEnv::beginScopedLocale('en_GB');
|
||||||
|
$this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode());
|
||||||
|
unset($guard);
|
||||||
|
$this->assertEqual($original, PhabricatorEnv::getLocaleCode());
|
||||||
|
|
||||||
|
// Nest guards, then destroy them out of order.
|
||||||
|
$guard1 = PhabricatorEnv::beginScopedLocale('en_GB');
|
||||||
|
$this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode());
|
||||||
|
$guard2 = PhabricatorEnv::beginScopedLocale('en_A*');
|
||||||
|
$this->assertEqual('en_A*', PhabricatorEnv::getLocaleCode());
|
||||||
|
unset($guard1);
|
||||||
|
$this->assertEqual('en_A*', PhabricatorEnv::getLocaleCode());
|
||||||
|
unset($guard2);
|
||||||
|
$this->assertEqual($original, PhabricatorEnv::getLocaleCode());
|
||||||
|
|
||||||
|
// If you push `null`, that should mean "the default locale", not
|
||||||
|
// "the current locale".
|
||||||
|
$guard3 = PhabricatorEnv::beginScopedLocale('en_GB');
|
||||||
|
$this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode());
|
||||||
|
$guard4 = PhabricatorEnv::beginScopedLocale(null);
|
||||||
|
$this->assertEqual($original, PhabricatorEnv::getLocaleCode());
|
||||||
|
unset($guard4);
|
||||||
|
$this->assertEqual('en_GB', PhabricatorEnv::getLocaleCode());
|
||||||
|
unset($guard3);
|
||||||
|
$this->assertEqual($original, PhabricatorEnv::getLocaleCode());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue