refactor(i18n): split copy manifest by page

go
codex 2 weeks ago
parent 337e1d3ea4
commit 64f03baa34

@ -0,0 +1,32 @@
<?php
/**
* Factory shared by source-language copy fragments.
*
* Fragments contain only stable keys, Chinese baselines and rendering
* contracts. Administrator-owned target translations never belong here.
*/
return static function (
string $key,
string $scope,
string $page,
string $source,
string $kind = 'label',
array $parameters = [],
string $criticality = 'required',
bool $allowHide = false,
?string $toastTone = null
): array {
return [
'key' => $key,
'scope' => $scope,
'page' => $page,
'kind' => $kind,
'source' => $source,
'format' => $parameters === [] ? 'plain_text' : 'icu',
'parameters' => $parameters,
'criticality' => $criticality,
'allow_hide' => $allowHide,
'toast_tone' => $toastTone,
];
};

@ -26,6 +26,21 @@ $common = static function (
];
};
$pageEntries = [];
$pageEntryFiles = glob(__DIR__ . '/entries/*.php');
if (is_array($pageEntryFiles)) {
sort($pageEntryFiles, SORT_STRING);
foreach ($pageEntryFiles as $pageEntryFile) {
$fragment = require $pageEntryFile;
if (!is_array($fragment) || !array_is_list($fragment)) {
throw new RuntimeException(
'用户界面文案分片必须返回词条列表:' . $pageEntryFile
);
}
array_push($pageEntries, ...$fragment);
}
}
return [
'version' => 1,
'pages' => [
@ -54,7 +69,7 @@ return [
'user.tasks' => ['label' => '任务中心', 'scopes' => ['common', 'tasks']],
'user.tickets' => ['label' => '工单页', 'scopes' => ['common', 'tickets']],
],
'entries' => [
'entries' => array_merge([
$common('common.shell.user_center', '用户中心', 'navigation'),
$common('common.shell.sidebar.aria', '用户中心侧栏', 'aria_label'),
$common('common.shell.navigation.aria', '用户中心主导航', 'aria_label'),
@ -162,5 +177,5 @@ return [
'allow_hide' => false,
'toast_tone' => 'warning',
],
],
], $pageEntries),
];

Loading…
Cancel
Save