1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 00:32:42 +01:00

Allow user override translation and implement PhutilPerson

Test Plan:
Altered database.
Wrote a custom translation and selected it in preferences.
Verified that the text is custom translated.
Set language back to default.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1139

Differential Revision: https://secure.phabricator.com/D2757
This commit is contained in:
vrana 2012-06-14 18:08:06 -07:00
parent ec819c068c
commit 48ebcf0679
6 changed files with 63 additions and 6 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE `{$NAMESPACE}_user`.`user`
ADD `translation` varchar(64) COLLATE utf8_bin AFTER `sex`;

View file

@ -1908,7 +1908,11 @@ phutil_register_library_map(array(
'PhabricatorUIPagerExample' => 'PhabricatorUIExample', 'PhabricatorUIPagerExample' => 'PhabricatorUIExample',
'PhabricatorUITooltipExample' => 'PhabricatorUIExample', 'PhabricatorUITooltipExample' => 'PhabricatorUIExample',
'PhabricatorUnitsTestCase' => 'PhabricatorTestCase', 'PhabricatorUnitsTestCase' => 'PhabricatorTestCase',
'PhabricatorUser' => 'PhabricatorUserDAO', 'PhabricatorUser' =>
array(
0 => 'PhabricatorUserDAO',
1 => 'PhutilPerson',
),
'PhabricatorUserAccountSettingsPanelController' => 'PhabricatorUserSettingsPanelController', 'PhabricatorUserAccountSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
'PhabricatorUserConduitSettingsPanelController' => 'PhabricatorUserSettingsPanelController', 'PhabricatorUserConduitSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
'PhabricatorUserDAO' => 'PhabricatorLiskDAO', 'PhabricatorUserDAO' => 'PhabricatorLiskDAO',

View file

@ -60,6 +60,17 @@ abstract class PhabricatorController extends AphrontController {
} }
} }
$translation = $user->getTranslation();
if ($translation &&
$translation != PhabricatorEnv::getEnvConfig('translation.provider') &&
class_exists($translation) &&
is_subclass_of($translation, 'PhabricatorTranslation')) {
$translation = newv($translation, array());
PhutilTranslator::getInstance()
->setLanguage($translation->getLanguage())
->addTranslations($translation->getTranslations());
}
$request->setUser($user); $request->setUser($user);
if ($user->getIsDisabled() && $this->shouldRequireEnabledUser()) { if ($user->getIsDisabled() && $this->shouldRequireEnabledUser()) {

View file

@ -41,12 +41,16 @@ final class PhabricatorUserProfileSettingsPanelController
$profile->setBlurb($request->getStr('blurb')); $profile->setBlurb($request->getStr('blurb'));
$sex = $request->getStr('sex'); $sex = $request->getStr('sex');
if (in_array($sex, array('m', 'f'))) { $sexes = array(PhutilPerson::SEX_MALE, PhutilPerson::SEX_FEMALE);
if (in_array($sex, $sexes)) {
$user->setSex($sex); $user->setSex($sex);
} else { } else {
$user->setSex(null); $user->setSex(null);
} }
// Checked in runtime.
$user->setTranslation($request->getStr('translation'));
if (!empty($_FILES['image'])) { if (!empty($_FILES['image'])) {
$err = idx($_FILES['image'], 'error'); $err = idx($_FILES['image'], 'error');
if ($err != UPLOAD_ERR_NO_FILE) { if ($err != UPLOAD_ERR_NO_FILE) {
@ -111,11 +115,27 @@ final class PhabricatorUserProfileSettingsPanelController
$profile_uri = PhabricatorEnv::getURI('/p/'.$user->getUsername().'/'); $profile_uri = PhabricatorEnv::getURI('/p/'.$user->getUsername().'/');
$sexes = array( $sexes = array(
'' => 'Unknown', PhutilPerson::SEX_UNKNOWN => 'Unknown',
'm' => 'Male', PhutilPerson::SEX_MALE => 'Male',
'f' => 'Female', PhutilPerson::SEX_FEMALE => 'Female',
); );
$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();
}
asort($translations);
$default = PhabricatorEnv::newObjectFromConfig('translation.provider');
$translations = array(
'' => 'Sever Default ('.$default->getName().')',
) + $translations;
$form = new AphrontFormView(); $form = new AphrontFormView();
$form $form
->setUser($request->getUser()) ->setUser($request->getUser())
@ -133,6 +153,12 @@ final class PhabricatorUserProfileSettingsPanelController
->setLabel('Sex') ->setLabel('Sex')
->setName('sex') ->setName('sex')
->setValue($user->getSex())) ->setValue($user->getSex()))
->appendChild(
id(new AphrontFormSelectControl())
->setOptions($translations)
->setLabel('Translation')
->setName('translation')
->setValue($user->getTranslation()))
->appendChild( ->appendChild(
id(new AphrontFormMarkupControl()) id(new AphrontFormMarkupControl())
->setLabel('Profile URI') ->setLabel('Profile URI')

View file

@ -16,7 +16,7 @@
* limitations under the License. * limitations under the License.
*/ */
final class PhabricatorUser extends PhabricatorUserDAO { final class PhabricatorUser extends PhabricatorUserDAO implements PhutilPerson {
const SESSION_TABLE = 'phabricator_session'; const SESSION_TABLE = 'phabricator_session';
const NAMETOKEN_TABLE = 'user_nametoken'; const NAMETOKEN_TABLE = 'user_nametoken';
@ -25,6 +25,7 @@ final class PhabricatorUser extends PhabricatorUserDAO {
protected $userName; protected $userName;
protected $realName; protected $realName;
protected $sex; protected $sex;
protected $translation;
protected $passwordSalt; protected $passwordSalt;
protected $passwordHash; protected $passwordHash;
protected $profileImagePHID; protected $profileImagePHID;
@ -90,6 +91,11 @@ final class PhabricatorUser extends PhabricatorUserDAO {
return $this; return $this;
} }
// To satisfy PhutilPerson.
public function getSex() {
return $this->sex;
}
public function isLoggedIn() { public function isLoggedIn() {
return !($this->getPHID() === null); return !($this->getPHID() === null);
} }
@ -624,6 +630,10 @@ EOBODY;
return $this->getUsername().' ('.$this->getRealName().')'; return $this->getUsername().' ('.$this->getRealName().')';
} }
public function __toString() {
return $this->getUsername();
}
public static function loadOneWithEmailAddress($address) { public static function loadOneWithEmailAddress($address) {
$email = id(new PhabricatorUserEmail())->loadOneWhere( $email = id(new PhabricatorUserEmail())->loadOneWhere(
'address = %s', 'address = %s',

View file

@ -891,6 +891,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
'type' => 'sql', 'type' => 'sql',
'name' => $this->getPatchPath('threadtopic.sql'), 'name' => $this->getPatchPath('threadtopic.sql'),
), ),
'usertranslation.sql' => array(
'type' => 'sql',
'name' => $this->getPatchPath('usertranslation.sql'),
),
); );
} }