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:
parent
ec819c068c
commit
48ebcf0679
6 changed files with 63 additions and 6 deletions
2
resources/sql/patches/usertranslation.sql
Normal file
2
resources/sql/patches/usertranslation.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE `{$NAMESPACE}_user`.`user`
|
||||
ADD `translation` varchar(64) COLLATE utf8_bin AFTER `sex`;
|
|
@ -1908,7 +1908,11 @@ phutil_register_library_map(array(
|
|||
'PhabricatorUIPagerExample' => 'PhabricatorUIExample',
|
||||
'PhabricatorUITooltipExample' => 'PhabricatorUIExample',
|
||||
'PhabricatorUnitsTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorUser' => 'PhabricatorUserDAO',
|
||||
'PhabricatorUser' =>
|
||||
array(
|
||||
0 => 'PhabricatorUserDAO',
|
||||
1 => 'PhutilPerson',
|
||||
),
|
||||
'PhabricatorUserAccountSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
|
||||
'PhabricatorUserConduitSettingsPanelController' => 'PhabricatorUserSettingsPanelController',
|
||||
'PhabricatorUserDAO' => 'PhabricatorLiskDAO',
|
||||
|
|
|
@ -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);
|
||||
|
||||
if ($user->getIsDisabled() && $this->shouldRequireEnabledUser()) {
|
||||
|
|
|
@ -41,12 +41,16 @@ final class PhabricatorUserProfileSettingsPanelController
|
|||
$profile->setBlurb($request->getStr('blurb'));
|
||||
|
||||
$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);
|
||||
} else {
|
||||
$user->setSex(null);
|
||||
}
|
||||
|
||||
// Checked in runtime.
|
||||
$user->setTranslation($request->getStr('translation'));
|
||||
|
||||
if (!empty($_FILES['image'])) {
|
||||
$err = idx($_FILES['image'], 'error');
|
||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||
|
@ -111,11 +115,27 @@ final class PhabricatorUserProfileSettingsPanelController
|
|||
$profile_uri = PhabricatorEnv::getURI('/p/'.$user->getUsername().'/');
|
||||
|
||||
$sexes = array(
|
||||
'' => 'Unknown',
|
||||
'm' => 'Male',
|
||||
'f' => 'Female',
|
||||
PhutilPerson::SEX_UNKNOWN => 'Unknown',
|
||||
PhutilPerson::SEX_MALE => 'Male',
|
||||
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
|
||||
->setUser($request->getUser())
|
||||
|
@ -133,6 +153,12 @@ final class PhabricatorUserProfileSettingsPanelController
|
|||
->setLabel('Sex')
|
||||
->setName('sex')
|
||||
->setValue($user->getSex()))
|
||||
->appendChild(
|
||||
id(new AphrontFormSelectControl())
|
||||
->setOptions($translations)
|
||||
->setLabel('Translation')
|
||||
->setName('translation')
|
||||
->setValue($user->getTranslation()))
|
||||
->appendChild(
|
||||
id(new AphrontFormMarkupControl())
|
||||
->setLabel('Profile URI')
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class PhabricatorUser extends PhabricatorUserDAO {
|
||||
final class PhabricatorUser extends PhabricatorUserDAO implements PhutilPerson {
|
||||
|
||||
const SESSION_TABLE = 'phabricator_session';
|
||||
const NAMETOKEN_TABLE = 'user_nametoken';
|
||||
|
@ -25,6 +25,7 @@ final class PhabricatorUser extends PhabricatorUserDAO {
|
|||
protected $userName;
|
||||
protected $realName;
|
||||
protected $sex;
|
||||
protected $translation;
|
||||
protected $passwordSalt;
|
||||
protected $passwordHash;
|
||||
protected $profileImagePHID;
|
||||
|
@ -90,6 +91,11 @@ final class PhabricatorUser extends PhabricatorUserDAO {
|
|||
return $this;
|
||||
}
|
||||
|
||||
// To satisfy PhutilPerson.
|
||||
public function getSex() {
|
||||
return $this->sex;
|
||||
}
|
||||
|
||||
public function isLoggedIn() {
|
||||
return !($this->getPHID() === null);
|
||||
}
|
||||
|
@ -624,6 +630,10 @@ EOBODY;
|
|||
return $this->getUsername().' ('.$this->getRealName().')';
|
||||
}
|
||||
|
||||
public function __toString() {
|
||||
return $this->getUsername();
|
||||
}
|
||||
|
||||
public static function loadOneWithEmailAddress($address) {
|
||||
$email = id(new PhabricatorUserEmail())->loadOneWhere(
|
||||
'address = %s',
|
||||
|
|
|
@ -891,6 +891,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
|||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('threadtopic.sql'),
|
||||
),
|
||||
'usertranslation.sql' => array(
|
||||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('usertranslation.sql'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue