1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02: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:
vrana 2012-06-14 13:43:09 -07:00
parent 357305507c
commit 0acb7734cd
14 changed files with 154 additions and 68 deletions

View file

@ -65,6 +65,13 @@ return array(
'phabricator.custom.logo' => null,
// -- Internationalization -------------------------------------------------- //
// This allows customizing texts used in Phabricator. The class must extend
// PhabricatorTranslation.
'translation.provider' => 'PhabricatorEnglishTranslation',
// -- Access Policies ------------------------------------------------------- //
// Phabricator allows you to set the visibility of objects (like repositories

View file

@ -60,6 +60,11 @@ $conf['phabricator.env'] = $env;
PhabricatorEnv::setEnvConfig($conf);
$translation = PhabricatorEnv::newObjectFromConfig('translation.provider');
PhutilTranslator::getInstance()
->setLanguage($translation->getLanguage())
->addTranslations($translation->getTranslations());
phutil_load_library('arcanist/src');
foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) {

View file

@ -614,6 +614,7 @@ phutil_register_library_map(array(
'PhabricatorEmailLoginController' => 'applications/auth/controller/PhabricatorEmailLoginController.php',
'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php',
'PhabricatorEmailVerificationController' => 'applications/people/controller/PhabricatorEmailVerificationController.php',
'PhabricatorEnglishTranslation' => 'infrastructure/internationalization/PhabricatorEnglishTranslation.php',
'PhabricatorEnv' => 'infrastructure/PhabricatorEnv.php',
'PhabricatorEnvTestCase' => 'infrastructure/__tests__/PhabricatorEnvTestCase.php',
'PhabricatorErrorExample' => 'applications/uiexample/examples/PhabricatorErrorExample.php',
@ -959,6 +960,7 @@ phutil_register_library_map(array(
'PhabricatorTimer' => 'applications/countdown/storage/PhabricatorTimer.php',
'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php',
'PhabricatorTransformedFile' => 'applications/files/storage/PhabricatorTransformedFile.php',
'PhabricatorTranslation' => 'infrastructure/internationalization/PhabricatorTranslation.php',
'PhabricatorTrivialTestCase' => 'infrastructure/testing/__tests__/PhabricatorTrivialTestCase.php',
'PhabricatorTypeaheadCommonDatasourceController' => 'applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php',
'PhabricatorTypeaheadDatasourceController' => 'applications/typeahead/controller/PhabricatorTypeaheadDatasourceController.php',
@ -1609,6 +1611,7 @@ phutil_register_library_map(array(
'PhabricatorEmailLoginController' => 'PhabricatorAuthController',
'PhabricatorEmailTokenController' => 'PhabricatorAuthController',
'PhabricatorEmailVerificationController' => 'PhabricatorPeopleController',
'PhabricatorEnglishTranslation' => 'PhabricatorTranslation',
'PhabricatorEnvTestCase' => 'PhabricatorTestCase',
'PhabricatorErrorExample' => 'PhabricatorUIExample',
'PhabricatorEvent' => 'PhutilEvent',

View file

@ -64,14 +64,7 @@ final class DifferentialCommitsFieldSpecification
$body = array();
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
if (count($handles) == 1) {
$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";
}
$body[] = pht('COMMIT(S)', count($handles));
foreach ($handles as $handle) {
$body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI());

View file

@ -167,28 +167,27 @@ final class DifferentialLintFieldSpecification
'details',
)) + $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();
foreach ($hidden as $key => $value) {
if ($value == 1) {
$show[] = $value.' '.idx($singular, $key);
} else {
$show[] = $value.' '.idx($plural, $key);
switch ($key) {
case ArcanistLintSeverity::SEVERITY_ERROR:
$show[] = pht('%d Error(s)', $value);
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;
}
}

View file

@ -171,13 +171,16 @@ final class DifferentialUnitFieldSpecification
ArcanistUnitTestResult::RESULT_SKIP => 'Skipped',
ArcanistUnitTestResult::RESULT_POSTPONED => 'Postponed',
ArcanistUnitTestResult::RESULT_PASS => 'Passed',
'details' => 'Details',
);
$show = array();
foreach ($hidden as $key => $value) {
if ($key == 'details') {
$show[] = pht('%d Detail(s)', $value);
} else {
$show[] = $value.' '.idx($noun, $key);
}
}
return "Show Full Unit Results (".implode(', ', $show).")";
}

View file

@ -21,7 +21,7 @@ final class DifferentialNewDiffMail extends DifferentialReviewRequestMail {
protected function renderVaryPrefix() {
$revision = $this->getRevision();
$line_count = $revision->getLineCount();
$lines = ($line_count == 1 ? "1 line" : "{$line_count} lines");
$lines = pht('%d line(s)', $line_count);
if ($this->isFirstMailToRecipients()) {
$verb = 'Request';

View file

@ -137,10 +137,8 @@ final class DifferentialDiffTableOfContentsView extends AphrontView {
$line_count = $changeset->getAffectedLineCount();
if ($line_count == 0) {
$lines = null;
} else if ($line_count == 1) {
$lines = ' (1 line)';
} else {
$lines = ' ('.$line_count.' lines)';
$lines = ' '.pht('(%d line(s))', $line_count);
}
$char = DifferentialChangeType::getSummaryCharacterForChangeType($type);

View file

@ -407,7 +407,7 @@ final class ManiphestTransactionDetailView extends ManiphestView {
if (count($removed) == 1) {
$desc = 'removed project '.$this->renderHandles($removed);
} else {
$desc = 'removed projectss: '.$this->renderHandles($removed);
$desc = 'removed projects: '.$this->renderHandles($removed);
}
} else {
$verb = 'Changed Projects';
@ -488,39 +488,20 @@ final class ManiphestTransactionDetailView extends ManiphestView {
$add_desc = $this->renderHandles($added);
$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) {
$verb = 'Attached';
if (count($added) == 1) {
$desc = 'attached '.$singular.': '.$add_desc;
} else {
$desc = 'attached '.$plural.': '.$add_desc;
}
$desc = 'attached '.$this->getAttachName($attach_type, count($added));
} else if ($removed && !$added) {
$verb = 'Detached';
if (count($removed) == 1) {
$desc = 'detached '.$singular.': '.$rem_desc;
} else {
$desc = 'detached '.$plural.': '.$rem_desc;
}
$desc =
'detached '.
$this->getAttachName($attach_type, count($removed));
} else {
$verb = 'Changed Attached';
$desc = 'changed attached '.$plural.', added: '.$add_desc.'; '.
$desc =
'changed attached '.
$this->getAttachName($attach_type, count($added) + count($removed)).
', added: '.$add_desc.'; '.
'removed: '.$rem_desc;
}
break;
@ -565,6 +546,17 @@ final class ManiphestTransactionDetailView extends ManiphestView {
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) {
switch ($transaction->getTransactionType()) {
case ManiphestTransactionType::TYPE_DESCRIPTION:

View file

@ -144,11 +144,9 @@ extends PhortuneStripeBaseController {
}
// append a helpful "fix this" to the messages to be displayed to the user
if (count($messages) == 1) {
$messages[] = 'Please fix this error and try again.';
} else {
$messages[] = 'Please fix these errors and try again.';
}
$messages[] = pht(
'Please fix these errors and try again.',
count($messages));
return array(
$card_number_error,

View file

@ -299,6 +299,7 @@ final class PhabricatorEnv {
*/
public static function getRequiredClasses() {
return array(
'translation.provider' => 'PhabricatorTranslation',
'metamta.mail-adapter' => 'PhabricatorMailImplementationAdapter',
'metamta.maniphest.reply-handler' => 'PhabricatorMailReplyHandler',
'metamta.differential.reply-handler' => 'PhabricatorMailReplyHandler',

View file

@ -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'),
);
}
}

View file

@ -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();
}

View file

@ -122,6 +122,11 @@ if (PhabricatorEnv::getEnvConfig('phabricator.setup')) {
phabricator_detect_bad_base_uri();
$translation = PhabricatorEnv::newObjectFromConfig('translation.provider');
PhutilTranslator::getInstance()
->setLanguage($translation->getLanguage())
->addTranslations($translation->getTranslations());
$host = $_SERVER['HTTP_HOST'];
$path = $_REQUEST['__path__'];