mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Use pht()
Summary: This is the first step in Phabricator internationalization. It adds a translation selector and calls it at startup. Installations can add custom selectors to override some texts. We can add official translations in future. Next step is to allow user to choose his translation which will override the global one. This is currently used only for English plurals. Test Plan: Displayed a diff with unit test error, verified that it says 'Detail' or 'Details' and not 'Detail(s)'. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1139 Differential Revision: https://secure.phabricator.com/D2753
This commit is contained in:
parent
357305507c
commit
0acb7734cd
14 changed files with 154 additions and 68 deletions
|
@ -65,6 +65,13 @@ return array(
|
||||||
'phabricator.custom.logo' => null,
|
'phabricator.custom.logo' => null,
|
||||||
|
|
||||||
|
|
||||||
|
// -- Internationalization -------------------------------------------------- //
|
||||||
|
|
||||||
|
// This allows customizing texts used in Phabricator. The class must extend
|
||||||
|
// PhabricatorTranslation.
|
||||||
|
'translation.provider' => 'PhabricatorEnglishTranslation',
|
||||||
|
|
||||||
|
|
||||||
// -- Access Policies ------------------------------------------------------- //
|
// -- Access Policies ------------------------------------------------------- //
|
||||||
|
|
||||||
// Phabricator allows you to set the visibility of objects (like repositories
|
// Phabricator allows you to set the visibility of objects (like repositories
|
||||||
|
|
|
@ -60,6 +60,11 @@ $conf['phabricator.env'] = $env;
|
||||||
|
|
||||||
PhabricatorEnv::setEnvConfig($conf);
|
PhabricatorEnv::setEnvConfig($conf);
|
||||||
|
|
||||||
|
$translation = PhabricatorEnv::newObjectFromConfig('translation.provider');
|
||||||
|
PhutilTranslator::getInstance()
|
||||||
|
->setLanguage($translation->getLanguage())
|
||||||
|
->addTranslations($translation->getTranslations());
|
||||||
|
|
||||||
phutil_load_library('arcanist/src');
|
phutil_load_library('arcanist/src');
|
||||||
|
|
||||||
foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) {
|
foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) {
|
||||||
|
|
|
@ -614,6 +614,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php',
|
'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php',
|
||||||
'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php',
|
'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php',
|
||||||
'PhabricatorEmailVerificationController' => 'applications/people/controller/PhabricatorEmailVerificationController.php',
|
'PhabricatorEmailVerificationController' => 'applications/people/controller/PhabricatorEmailVerificationController.php',
|
||||||
|
'PhabricatorEnglishTranslation' => 'infrastructure/internationalization/PhabricatorEnglishTranslation.php',
|
||||||
'PhabricatorEnv' => 'infrastructure/PhabricatorEnv.php',
|
'PhabricatorEnv' => 'infrastructure/PhabricatorEnv.php',
|
||||||
'PhabricatorEnvTestCase' => 'infrastructure/__tests__/PhabricatorEnvTestCase.php',
|
'PhabricatorEnvTestCase' => 'infrastructure/__tests__/PhabricatorEnvTestCase.php',
|
||||||
'PhabricatorErrorExample' => 'applications/uiexample/examples/PhabricatorErrorExample.php',
|
'PhabricatorErrorExample' => 'applications/uiexample/examples/PhabricatorErrorExample.php',
|
||||||
|
@ -959,6 +960,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorTimer' => 'applications/countdown/storage/PhabricatorTimer.php',
|
'PhabricatorTimer' => 'applications/countdown/storage/PhabricatorTimer.php',
|
||||||
'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php',
|
'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php',
|
||||||
'PhabricatorTransformedFile' => 'applications/files/storage/PhabricatorTransformedFile.php',
|
'PhabricatorTransformedFile' => 'applications/files/storage/PhabricatorTransformedFile.php',
|
||||||
|
'PhabricatorTranslation' => 'infrastructure/internationalization/PhabricatorTranslation.php',
|
||||||
'PhabricatorTrivialTestCase' => 'infrastructure/testing/__tests__/PhabricatorTrivialTestCase.php',
|
'PhabricatorTrivialTestCase' => 'infrastructure/testing/__tests__/PhabricatorTrivialTestCase.php',
|
||||||
'PhabricatorTypeaheadCommonDatasourceController' => 'applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php',
|
'PhabricatorTypeaheadCommonDatasourceController' => 'applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php',
|
||||||
'PhabricatorTypeaheadDatasourceController' => 'applications/typeahead/controller/PhabricatorTypeaheadDatasourceController.php',
|
'PhabricatorTypeaheadDatasourceController' => 'applications/typeahead/controller/PhabricatorTypeaheadDatasourceController.php',
|
||||||
|
@ -1609,6 +1611,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorEmailLoginController' => 'PhabricatorAuthController',
|
'PhabricatorEmailLoginController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorEmailTokenController' => 'PhabricatorAuthController',
|
'PhabricatorEmailTokenController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorEmailVerificationController' => 'PhabricatorPeopleController',
|
'PhabricatorEmailVerificationController' => 'PhabricatorPeopleController',
|
||||||
|
'PhabricatorEnglishTranslation' => 'PhabricatorTranslation',
|
||||||
'PhabricatorEnvTestCase' => 'PhabricatorTestCase',
|
'PhabricatorEnvTestCase' => 'PhabricatorTestCase',
|
||||||
'PhabricatorErrorExample' => 'PhabricatorUIExample',
|
'PhabricatorErrorExample' => 'PhabricatorUIExample',
|
||||||
'PhabricatorEvent' => 'PhutilEvent',
|
'PhabricatorEvent' => 'PhutilEvent',
|
||||||
|
|
|
@ -64,14 +64,7 @@ final class DifferentialCommitsFieldSpecification
|
||||||
|
|
||||||
$body = array();
|
$body = array();
|
||||||
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
|
||||||
if (count($handles) == 1) {
|
$body[] = pht('COMMIT(S)', count($handles));
|
||||||
$body[] = "COMMIT";
|
|
||||||
} else {
|
|
||||||
// This is unlikely to ever happen since we'll send this mail the
|
|
||||||
// first time we discover a commit, but it's not impossible if data
|
|
||||||
// was migrated, etc.
|
|
||||||
$body[] = "COMMITS";
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($handles as $handle) {
|
foreach ($handles as $handle) {
|
||||||
$body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI());
|
$body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI());
|
||||||
|
|
|
@ -167,28 +167,27 @@ final class DifferentialLintFieldSpecification
|
||||||
'details',
|
'details',
|
||||||
)) + $hidden;
|
)) + $hidden;
|
||||||
|
|
||||||
$singular = array(
|
|
||||||
ArcanistLintSeverity::SEVERITY_ERROR => 'Error',
|
|
||||||
ArcanistLintSeverity::SEVERITY_WARNING => 'Warning',
|
|
||||||
ArcanistLintSeverity::SEVERITY_AUTOFIX => 'Auto-Fix',
|
|
||||||
ArcanistLintSeverity::SEVERITY_ADVICE => 'Advice',
|
|
||||||
'details' => 'Detail',
|
|
||||||
);
|
|
||||||
|
|
||||||
$plural = array(
|
|
||||||
ArcanistLintSeverity::SEVERITY_ERROR => 'Errors',
|
|
||||||
ArcanistLintSeverity::SEVERITY_WARNING => 'Warnings',
|
|
||||||
ArcanistLintSeverity::SEVERITY_AUTOFIX => 'Auto-Fixes',
|
|
||||||
ArcanistLintSeverity::SEVERITY_ADVICE => 'Advice',
|
|
||||||
'details' => 'Details',
|
|
||||||
);
|
|
||||||
|
|
||||||
$show = array();
|
$show = array();
|
||||||
foreach ($hidden as $key => $value) {
|
foreach ($hidden as $key => $value) {
|
||||||
if ($value == 1) {
|
switch ($key) {
|
||||||
$show[] = $value.' '.idx($singular, $key);
|
case ArcanistLintSeverity::SEVERITY_ERROR:
|
||||||
} else {
|
$show[] = pht('%d Error(s)', $value);
|
||||||
$show[] = $value.' '.idx($plural, $key);
|
break;
|
||||||
|
case ArcanistLintSeverity::SEVERITY_WARNING:
|
||||||
|
$show[] = pht('%d Warning(s)', $value);
|
||||||
|
break;
|
||||||
|
case ArcanistLintSeverity::SEVERITY_AUTOFIX:
|
||||||
|
$show[] = pht('%d Auto-Fix(es)', $value);
|
||||||
|
break;
|
||||||
|
case ArcanistLintSeverity::SEVERITY_ADVICE:
|
||||||
|
$show[] = pht('%d Advice(s)', $value);
|
||||||
|
break;
|
||||||
|
case 'details':
|
||||||
|
$show[] = pht('%d Detail(s)', $value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$show[] = $value;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,12 +171,15 @@ final class DifferentialUnitFieldSpecification
|
||||||
ArcanistUnitTestResult::RESULT_SKIP => 'Skipped',
|
ArcanistUnitTestResult::RESULT_SKIP => 'Skipped',
|
||||||
ArcanistUnitTestResult::RESULT_POSTPONED => 'Postponed',
|
ArcanistUnitTestResult::RESULT_POSTPONED => 'Postponed',
|
||||||
ArcanistUnitTestResult::RESULT_PASS => 'Passed',
|
ArcanistUnitTestResult::RESULT_PASS => 'Passed',
|
||||||
'details' => 'Details',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$show = array();
|
$show = array();
|
||||||
foreach ($hidden as $key => $value) {
|
foreach ($hidden as $key => $value) {
|
||||||
$show[] = $value.' '.idx($noun, $key);
|
if ($key == 'details') {
|
||||||
|
$show[] = pht('%d Detail(s)', $value);
|
||||||
|
} else {
|
||||||
|
$show[] = $value.' '.idx($noun, $key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "Show Full Unit Results (".implode(', ', $show).")";
|
return "Show Full Unit Results (".implode(', ', $show).")";
|
||||||
|
|
|
@ -21,7 +21,7 @@ final class DifferentialNewDiffMail extends DifferentialReviewRequestMail {
|
||||||
protected function renderVaryPrefix() {
|
protected function renderVaryPrefix() {
|
||||||
$revision = $this->getRevision();
|
$revision = $this->getRevision();
|
||||||
$line_count = $revision->getLineCount();
|
$line_count = $revision->getLineCount();
|
||||||
$lines = ($line_count == 1 ? "1 line" : "{$line_count} lines");
|
$lines = pht('%d line(s)', $line_count);
|
||||||
|
|
||||||
if ($this->isFirstMailToRecipients()) {
|
if ($this->isFirstMailToRecipients()) {
|
||||||
$verb = 'Request';
|
$verb = 'Request';
|
||||||
|
|
|
@ -137,10 +137,8 @@ final class DifferentialDiffTableOfContentsView extends AphrontView {
|
||||||
$line_count = $changeset->getAffectedLineCount();
|
$line_count = $changeset->getAffectedLineCount();
|
||||||
if ($line_count == 0) {
|
if ($line_count == 0) {
|
||||||
$lines = null;
|
$lines = null;
|
||||||
} else if ($line_count == 1) {
|
|
||||||
$lines = ' (1 line)';
|
|
||||||
} else {
|
} else {
|
||||||
$lines = ' ('.$line_count.' lines)';
|
$lines = ' '.pht('(%d line(s))', $line_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
$char = DifferentialChangeType::getSummaryCharacterForChangeType($type);
|
$char = DifferentialChangeType::getSummaryCharacterForChangeType($type);
|
||||||
|
|
|
@ -407,7 +407,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
if (count($removed) == 1) {
|
if (count($removed) == 1) {
|
||||||
$desc = 'removed project '.$this->renderHandles($removed);
|
$desc = 'removed project '.$this->renderHandles($removed);
|
||||||
} else {
|
} else {
|
||||||
$desc = 'removed projectss: '.$this->renderHandles($removed);
|
$desc = 'removed projects: '.$this->renderHandles($removed);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$verb = 'Changed Projects';
|
$verb = 'Changed Projects';
|
||||||
|
@ -488,40 +488,21 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
$add_desc = $this->renderHandles($added);
|
$add_desc = $this->renderHandles($added);
|
||||||
$rem_desc = $this->renderHandles($removed);
|
$rem_desc = $this->renderHandles($removed);
|
||||||
|
|
||||||
switch ($attach_type) {
|
|
||||||
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
|
||||||
$singular = 'Differential Revision';
|
|
||||||
$plural = 'Differential Revisions';
|
|
||||||
break;
|
|
||||||
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
|
|
||||||
$singular = 'file';
|
|
||||||
$plural = 'files';
|
|
||||||
break;
|
|
||||||
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
|
|
||||||
$singular = 'Maniphest Task';
|
|
||||||
$plural = 'Maniphest Tasks';
|
|
||||||
$dependency = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($added && !$removed) {
|
if ($added && !$removed) {
|
||||||
$verb = 'Attached';
|
$verb = 'Attached';
|
||||||
if (count($added) == 1) {
|
$desc = 'attached '.$this->getAttachName($attach_type, count($added));
|
||||||
$desc = 'attached '.$singular.': '.$add_desc;
|
|
||||||
} else {
|
|
||||||
$desc = 'attached '.$plural.': '.$add_desc;
|
|
||||||
}
|
|
||||||
} else if ($removed && !$added) {
|
} else if ($removed && !$added) {
|
||||||
$verb = 'Detached';
|
$verb = 'Detached';
|
||||||
if (count($removed) == 1) {
|
$desc =
|
||||||
$desc = 'detached '.$singular.': '.$rem_desc;
|
'detached '.
|
||||||
} else {
|
$this->getAttachName($attach_type, count($removed));
|
||||||
$desc = 'detached '.$plural.': '.$rem_desc;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$verb = 'Changed Attached';
|
$verb = 'Changed Attached';
|
||||||
$desc = 'changed attached '.$plural.', added: '.$add_desc.'; '.
|
$desc =
|
||||||
'removed: '.$rem_desc;
|
'changed attached '.
|
||||||
|
$this->getAttachName($attach_type, count($added) + count($removed)).
|
||||||
|
', added: '.$add_desc.'; '.
|
||||||
|
'removed: '.$rem_desc;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ManiphestTransactionType::TYPE_AUXILIARY:
|
case ManiphestTransactionType::TYPE_AUXILIARY:
|
||||||
|
@ -565,6 +546,17 @@ final class ManiphestTransactionDetailView extends ManiphestView {
|
||||||
return array($verb, $desc, $classes);
|
return array($verb, $desc, $classes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getAttachName($attach_type, $count) {
|
||||||
|
switch ($attach_type) {
|
||||||
|
case PhabricatorPHIDConstants::PHID_TYPE_DREV:
|
||||||
|
return pht('Differential Revision(s)', $count);
|
||||||
|
case PhabricatorPHIDConstants::PHID_TYPE_FILE:
|
||||||
|
return pht('file(s)', $count);
|
||||||
|
case PhabricatorPHIDConstants::PHID_TYPE_TASK:
|
||||||
|
return pht('Maniphest Task(s)', $count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function renderFullSummary($transaction) {
|
private function renderFullSummary($transaction) {
|
||||||
switch ($transaction->getTransactionType()) {
|
switch ($transaction->getTransactionType()) {
|
||||||
case ManiphestTransactionType::TYPE_DESCRIPTION:
|
case ManiphestTransactionType::TYPE_DESCRIPTION:
|
||||||
|
|
|
@ -144,11 +144,9 @@ extends PhortuneStripeBaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
// append a helpful "fix this" to the messages to be displayed to the user
|
// append a helpful "fix this" to the messages to be displayed to the user
|
||||||
if (count($messages) == 1) {
|
$messages[] = pht(
|
||||||
$messages[] = 'Please fix this error and try again.';
|
'Please fix these errors and try again.',
|
||||||
} else {
|
count($messages));
|
||||||
$messages[] = 'Please fix these errors and try again.';
|
|
||||||
}
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
$card_number_error,
|
$card_number_error,
|
||||||
|
|
|
@ -299,6 +299,7 @@ final class PhabricatorEnv {
|
||||||
*/
|
*/
|
||||||
public static function getRequiredClasses() {
|
public static function getRequiredClasses() {
|
||||||
return array(
|
return array(
|
||||||
|
'translation.provider' => 'PhabricatorTranslation',
|
||||||
'metamta.mail-adapter' => 'PhabricatorMailImplementationAdapter',
|
'metamta.mail-adapter' => 'PhabricatorMailImplementationAdapter',
|
||||||
'metamta.maniphest.reply-handler' => 'PhabricatorMailReplyHandler',
|
'metamta.maniphest.reply-handler' => 'PhabricatorMailReplyHandler',
|
||||||
'metamta.differential.reply-handler' => 'PhabricatorMailReplyHandler',
|
'metamta.differential.reply-handler' => 'PhabricatorMailReplyHandler',
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
final class PhabricatorEnglishTranslation extends PhabricatorTranslation {
|
||||||
|
|
||||||
|
public function getLanguage() {
|
||||||
|
return 'en';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName() {
|
||||||
|
return 'English';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTranslations() {
|
||||||
|
return array(
|
||||||
|
'Differential Revision(s)' => array(
|
||||||
|
'Differential Revision',
|
||||||
|
'Differential Revisions',
|
||||||
|
),
|
||||||
|
'file(s)' => array('file', 'files'),
|
||||||
|
'Maniphest Task(s)' => array('Maniphest Task', 'Maniphest Tasks'),
|
||||||
|
|
||||||
|
'Please fix these errors and try again.' => array(
|
||||||
|
'Please fix this error and try again.',
|
||||||
|
'Please fix these errors and try again.',
|
||||||
|
),
|
||||||
|
|
||||||
|
'%d Error(s)' => array('%d Error', '%d Errors'),
|
||||||
|
'%d Warning(s)' => array('%d Warning', '%d Warnings'),
|
||||||
|
'%d Auto-Fix(es)' => array('%d Auto-Fix', '%d Auto-Fixes'),
|
||||||
|
'%d Advice(s)' => array('%d Advice', '%d Pieces of Advice'),
|
||||||
|
'%d Detail(s)' => array('%d Detail', '%d Details'),
|
||||||
|
|
||||||
|
'(%d line(s))' => array('(%d line)', '(%d lines)'),
|
||||||
|
|
||||||
|
'COMMIT(S)' => array('COMMIT', 'COMMITS'),
|
||||||
|
|
||||||
|
'%d line(s)' => array('%d line', '%d lines'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
abstract class PhabricatorTranslation {
|
||||||
|
|
||||||
|
abstract public function getLanguage();
|
||||||
|
abstract public function getName();
|
||||||
|
abstract public function getTranslations();
|
||||||
|
|
||||||
|
}
|
|
@ -122,6 +122,11 @@ if (PhabricatorEnv::getEnvConfig('phabricator.setup')) {
|
||||||
|
|
||||||
phabricator_detect_bad_base_uri();
|
phabricator_detect_bad_base_uri();
|
||||||
|
|
||||||
|
$translation = PhabricatorEnv::newObjectFromConfig('translation.provider');
|
||||||
|
PhutilTranslator::getInstance()
|
||||||
|
->setLanguage($translation->getLanguage())
|
||||||
|
->addTranslations($translation->getTranslations());
|
||||||
|
|
||||||
$host = $_SERVER['HTTP_HOST'];
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
$path = $_REQUEST['__path__'];
|
$path = $_REQUEST['__path__'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue