mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-28 23:48:19 +01:00
Write a very basic string extractor
Summary: Ref T1139. This has some issues and glitches, but is a reasonable initial attempt that gets some of the big pieces in. We have about 5,200 strings in Phabricator. Test Plan: {F108261} Reviewers: btrahan Reviewed By: btrahan CC: aran, chad Maniphest Tasks: T1139 Differential Revision: https://secure.phabricator.com/D8138
This commit is contained in:
parent
ad81700b65
commit
0726411cb4
10 changed files with 136 additions and 5 deletions
1
bin/i18n
Symbolic link
1
bin/i18n
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../scripts/setup/manage_i18n.php
|
21
scripts/setup/manage_i18n.php
Executable file
21
scripts/setup/manage_i18n.php
Executable file
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$root = dirname(dirname(dirname(__FILE__)));
|
||||||
|
require_once $root.'/scripts/__init_script__.php';
|
||||||
|
|
||||||
|
$args = new PhutilArgumentParser($argv);
|
||||||
|
$args->setTagline('manage internationalization');
|
||||||
|
$args->setSynopsis(<<<EOSYNOPSIS
|
||||||
|
**i18n** __command__ [__options__]
|
||||||
|
Manage translations and internationalization.
|
||||||
|
|
||||||
|
EOSYNOPSIS
|
||||||
|
);
|
||||||
|
$args->parseStandardArguments();
|
||||||
|
|
||||||
|
$workflows = id(new PhutilSymbolLoader())
|
||||||
|
->setAncestorClass('PhabricatorInternationalizationManagementWorkflow')
|
||||||
|
->loadObjects();
|
||||||
|
$workflows[] = new PhutilHelpArgumentWorkflow();
|
||||||
|
$args->parseWorkflows($workflows);
|
|
@ -1066,7 +1066,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorActionListExample' => 'applications/uiexample/examples/PhabricatorActionListExample.php',
|
'PhabricatorActionListExample' => 'applications/uiexample/examples/PhabricatorActionListExample.php',
|
||||||
'PhabricatorActionListView' => 'view/layout/PhabricatorActionListView.php',
|
'PhabricatorActionListView' => 'view/layout/PhabricatorActionListView.php',
|
||||||
'PhabricatorActionView' => 'view/layout/PhabricatorActionView.php',
|
'PhabricatorActionView' => 'view/layout/PhabricatorActionView.php',
|
||||||
'PhabricatorAllCapsTranslation' => 'infrastructure/internationalization/PhabricatorAllCapsTranslation.php',
|
'PhabricatorAllCapsTranslation' => 'infrastructure/internationalization/translation/PhabricatorAllCapsTranslation.php',
|
||||||
'PhabricatorAnchorView' => 'view/layout/PhabricatorAnchorView.php',
|
'PhabricatorAnchorView' => 'view/layout/PhabricatorAnchorView.php',
|
||||||
'PhabricatorAphrontBarExample' => 'applications/uiexample/examples/PhabricatorAphrontBarExample.php',
|
'PhabricatorAphrontBarExample' => 'applications/uiexample/examples/PhabricatorAphrontBarExample.php',
|
||||||
'PhabricatorAphrontViewTestCase' => 'view/__tests__/PhabricatorAphrontViewTestCase.php',
|
'PhabricatorAphrontViewTestCase' => 'view/__tests__/PhabricatorAphrontViewTestCase.php',
|
||||||
|
@ -1230,7 +1230,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorAuthenticationConfigOptions' => 'applications/config/option/PhabricatorAuthenticationConfigOptions.php',
|
'PhabricatorAuthenticationConfigOptions' => 'applications/config/option/PhabricatorAuthenticationConfigOptions.php',
|
||||||
'PhabricatorBarePageExample' => 'applications/uiexample/examples/PhabricatorBarePageExample.php',
|
'PhabricatorBarePageExample' => 'applications/uiexample/examples/PhabricatorBarePageExample.php',
|
||||||
'PhabricatorBarePageView' => 'view/page/PhabricatorBarePageView.php',
|
'PhabricatorBarePageView' => 'view/page/PhabricatorBarePageView.php',
|
||||||
'PhabricatorBaseEnglishTranslation' => 'infrastructure/internationalization/PhabricatorBaseEnglishTranslation.php',
|
'PhabricatorBaseEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorBaseEnglishTranslation.php',
|
||||||
'PhabricatorBaseProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorBaseProtocolAdapter.php',
|
'PhabricatorBaseProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorBaseProtocolAdapter.php',
|
||||||
'PhabricatorBot' => 'infrastructure/daemon/bot/PhabricatorBot.php',
|
'PhabricatorBot' => 'infrastructure/daemon/bot/PhabricatorBot.php',
|
||||||
'PhabricatorBotBaseStreamingProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorBotBaseStreamingProtocolAdapter.php',
|
'PhabricatorBotBaseStreamingProtocolAdapter' => 'infrastructure/daemon/bot/adapter/PhabricatorBotBaseStreamingProtocolAdapter.php',
|
||||||
|
@ -1434,7 +1434,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php',
|
'PhabricatorEmailTokenController' => 'applications/auth/controller/PhabricatorEmailTokenController.php',
|
||||||
'PhabricatorEmailVerificationController' => 'applications/auth/controller/PhabricatorEmailVerificationController.php',
|
'PhabricatorEmailVerificationController' => 'applications/auth/controller/PhabricatorEmailVerificationController.php',
|
||||||
'PhabricatorEmptyQueryException' => 'infrastructure/query/PhabricatorEmptyQueryException.php',
|
'PhabricatorEmptyQueryException' => 'infrastructure/query/PhabricatorEmptyQueryException.php',
|
||||||
'PhabricatorEnglishTranslation' => 'infrastructure/internationalization/PhabricatorEnglishTranslation.php',
|
'PhabricatorEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorEnglishTranslation.php',
|
||||||
'PhabricatorEnv' => 'infrastructure/env/PhabricatorEnv.php',
|
'PhabricatorEnv' => 'infrastructure/env/PhabricatorEnv.php',
|
||||||
'PhabricatorEnvTestCase' => 'infrastructure/env/__tests__/PhabricatorEnvTestCase.php',
|
'PhabricatorEnvTestCase' => 'infrastructure/env/__tests__/PhabricatorEnvTestCase.php',
|
||||||
'PhabricatorErrorExample' => 'applications/uiexample/examples/PhabricatorErrorExample.php',
|
'PhabricatorErrorExample' => 'applications/uiexample/examples/PhabricatorErrorExample.php',
|
||||||
|
@ -1573,6 +1573,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorInlineCommentInterface' => 'infrastructure/diff/interface/PhabricatorInlineCommentInterface.php',
|
'PhabricatorInlineCommentInterface' => 'infrastructure/diff/interface/PhabricatorInlineCommentInterface.php',
|
||||||
'PhabricatorInlineCommentPreviewController' => 'infrastructure/diff/PhabricatorInlineCommentPreviewController.php',
|
'PhabricatorInlineCommentPreviewController' => 'infrastructure/diff/PhabricatorInlineCommentPreviewController.php',
|
||||||
'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php',
|
'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php',
|
||||||
|
'PhabricatorInternationalizationManagementExtractWorkflow' => 'infrastructure/internationalization/management/PhabricatorInternationalizationManagementExtractWorkflow.php',
|
||||||
|
'PhabricatorInternationalizationManagementWorkflow' => 'infrastructure/internationalization/management/PhabricatorInternationalizationManagementWorkflow.php',
|
||||||
'PhabricatorJavelinLinter' => 'infrastructure/lint/linter/PhabricatorJavelinLinter.php',
|
'PhabricatorJavelinLinter' => 'infrastructure/lint/linter/PhabricatorJavelinLinter.php',
|
||||||
'PhabricatorJumpNavHandler' => 'applications/search/engine/PhabricatorJumpNavHandler.php',
|
'PhabricatorJumpNavHandler' => 'applications/search/engine/PhabricatorJumpNavHandler.php',
|
||||||
'PhabricatorKeyValueDatabaseCache' => 'applications/cache/PhabricatorKeyValueDatabaseCache.php',
|
'PhabricatorKeyValueDatabaseCache' => 'applications/cache/PhabricatorKeyValueDatabaseCache.php',
|
||||||
|
@ -2098,7 +2100,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php',
|
'PhabricatorTransactionView' => 'view/layout/PhabricatorTransactionView.php',
|
||||||
'PhabricatorTransactions' => 'applications/transactions/constants/PhabricatorTransactions.php',
|
'PhabricatorTransactions' => 'applications/transactions/constants/PhabricatorTransactions.php',
|
||||||
'PhabricatorTransformedFile' => 'applications/files/storage/PhabricatorTransformedFile.php',
|
'PhabricatorTransformedFile' => 'applications/files/storage/PhabricatorTransformedFile.php',
|
||||||
'PhabricatorTranslation' => 'infrastructure/internationalization/PhabricatorTranslation.php',
|
'PhabricatorTranslation' => 'infrastructure/internationalization/translation/PhabricatorTranslation.php',
|
||||||
'PhabricatorTranslationsConfigOptions' => 'applications/config/option/PhabricatorTranslationsConfigOptions.php',
|
'PhabricatorTranslationsConfigOptions' => 'applications/config/option/PhabricatorTranslationsConfigOptions.php',
|
||||||
'PhabricatorTrivialTestCase' => 'infrastructure/testing/__tests__/PhabricatorTrivialTestCase.php',
|
'PhabricatorTrivialTestCase' => 'infrastructure/testing/__tests__/PhabricatorTrivialTestCase.php',
|
||||||
'PhabricatorTwoColumnExample' => 'applications/uiexample/examples/PhabricatorTwoColumnExample.php',
|
'PhabricatorTwoColumnExample' => 'applications/uiexample/examples/PhabricatorTwoColumnExample.php',
|
||||||
|
@ -4270,6 +4272,8 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorInlineCommentInterface' => 'PhabricatorMarkupInterface',
|
'PhabricatorInlineCommentInterface' => 'PhabricatorMarkupInterface',
|
||||||
'PhabricatorInlineCommentPreviewController' => 'PhabricatorController',
|
'PhabricatorInlineCommentPreviewController' => 'PhabricatorController',
|
||||||
'PhabricatorInlineSummaryView' => 'AphrontView',
|
'PhabricatorInlineSummaryView' => 'AphrontView',
|
||||||
|
'PhabricatorInternationalizationManagementExtractWorkflow' => 'PhabricatorInternationalizationManagementWorkflow',
|
||||||
|
'PhabricatorInternationalizationManagementWorkflow' => 'PhabricatorManagementWorkflow',
|
||||||
'PhabricatorJavelinLinter' => 'ArcanistLinter',
|
'PhabricatorJavelinLinter' => 'ArcanistLinter',
|
||||||
'PhabricatorKeyValueDatabaseCache' => 'PhutilKeyValueCache',
|
'PhabricatorKeyValueDatabaseCache' => 'PhutilKeyValueCache',
|
||||||
'PhabricatorLegalpadConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
'PhabricatorLegalpadConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||||
|
|
|
@ -357,7 +357,7 @@ final class AphrontRequest {
|
||||||
'This Phabricator install is configured as "%s", but you are '.
|
'This Phabricator install is configured as "%s", but you are '.
|
||||||
'using the domain name "%s" to access a page which is trying to '.
|
'using the domain name "%s" to access a page which is trying to '.
|
||||||
'set a cookie. Acccess Phabricator on the configured primary '.
|
'set a cookie. Acccess Phabricator on the configured primary '.
|
||||||
'domain or a configured alternate domain. Phabricator will not '.
|
'domain or a configured alternate domain. Phabricator will not '.
|
||||||
'set cookies on other domains for security reasons.',
|
'set cookies on other domains for security reasons.',
|
||||||
$configured_as,
|
$configured_as,
|
||||||
$accessed_as));
|
$accessed_as));
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorInternationalizationManagementExtractWorkflow
|
||||||
|
extends PhabricatorInternationalizationManagementWorkflow {
|
||||||
|
|
||||||
|
public function didConstruct() {
|
||||||
|
$this
|
||||||
|
->setName('extract')
|
||||||
|
->setSynopsis(pht('Extract translatable strings.'))
|
||||||
|
->setArguments(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'name' => 'paths',
|
||||||
|
'wildcard' => true,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function execute(PhutilArgumentParser $args) {
|
||||||
|
$console = PhutilConsole::getConsole();
|
||||||
|
$paths = $args->getArg('paths');
|
||||||
|
|
||||||
|
$futures = array();
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
$root = Filesystem::resolvePath($path);
|
||||||
|
$path_files = id(new FileFinder($root))
|
||||||
|
->withType('f')
|
||||||
|
->withSuffix('php')
|
||||||
|
->find();
|
||||||
|
|
||||||
|
foreach ($path_files as $file) {
|
||||||
|
$full_path = $root.DIRECTORY_SEPARATOR.$file;
|
||||||
|
$data = Filesystem::readFile($full_path);
|
||||||
|
$futures[$full_path] = xhpast_get_parser_future($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$console->writeOut(
|
||||||
|
"%s\n",
|
||||||
|
pht('Found %s file(s)...', new PhutilNumber(count($futures))));
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
|
||||||
|
$bar = id(new PhutilConsoleProgressBar())
|
||||||
|
->setTotal(count($futures));
|
||||||
|
foreach (Futures($futures)->limit(8) as $full_path => $future) {
|
||||||
|
$bar->update(1);
|
||||||
|
|
||||||
|
$tree = XHPASTTree::newFromDataAndResolvedExecFuture(
|
||||||
|
Filesystem::readFile($full_path),
|
||||||
|
$future->resolve());
|
||||||
|
|
||||||
|
$root = $tree->getRootNode();
|
||||||
|
$calls = $root->selectDescendantsOfType('n_FUNCTION_CALL');
|
||||||
|
foreach ($calls as $call) {
|
||||||
|
$name = $call->getChildByIndex(0)->getConcreteString();
|
||||||
|
if ($name == 'pht') {
|
||||||
|
$params = $call->getChildByIndex(1, 'n_CALL_PARAMETER_LIST');
|
||||||
|
$string_node = $params->getChildByIndex(0);
|
||||||
|
$string_line = $string_node->getLineNumber();
|
||||||
|
try {
|
||||||
|
$string_value = $string_node->evalStatic();
|
||||||
|
|
||||||
|
$results[$string_value][] = array(
|
||||||
|
'file' => Filesystem::readablePath($full_path),
|
||||||
|
'line' => $string_line,
|
||||||
|
);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
// TODO: Deal with this junks.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$tree->dispose();
|
||||||
|
}
|
||||||
|
$bar->done();
|
||||||
|
|
||||||
|
ksort($results);
|
||||||
|
|
||||||
|
$out = array();
|
||||||
|
$out[] = '<?php';
|
||||||
|
$out[] = '// @nolint';
|
||||||
|
$out[] = 'return array(';
|
||||||
|
foreach ($results as $string => $locations) {
|
||||||
|
foreach ($locations as $location) {
|
||||||
|
$out[] = ' // '.$location['file'].':'.$location['line'];
|
||||||
|
}
|
||||||
|
$out[] = " '".addcslashes($string, "\0..\37\\'\177..\377")."' => null,";
|
||||||
|
$out[] = null;
|
||||||
|
}
|
||||||
|
$out[] = ');';
|
||||||
|
$out[] = null;
|
||||||
|
|
||||||
|
echo implode("\n", $out);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class PhabricatorInternationalizationManagementWorkflow
|
||||||
|
extends PhabricatorManagementWorkflow {
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue