fix(i18n): localize user operation titles
parent
6bff12f30c
commit
ebf9b58eba
@ -0,0 +1,19 @@
|
||||
const COPY_KEY_PATTERN = /^common\.operation\.(?:kind|action|setting)\.[a-z0-9_]+$/;
|
||||
|
||||
/** Render a user-facing operation title exclusively from stable copy keys. */
|
||||
export function operationTitle(entry, text, fallbackKey) {
|
||||
const translate = typeof text === 'function' ? text : () => '';
|
||||
const keys = Array.isArray(entry?.operation_copy_keys)
|
||||
? entry.operation_copy_keys.filter(key => (
|
||||
typeof key === 'string' && COPY_KEY_PATTERN.test(key)
|
||||
)) : [];
|
||||
const labels = keys.map(key => String(translate(key) || '').trim())
|
||||
.filter((label, index) => label && label !== keys[index]);
|
||||
if (labels.length) {
|
||||
const separator = String(
|
||||
translate('common.operation.list_separator') || ', ',
|
||||
);
|
||||
return labels.join(separator);
|
||||
}
|
||||
return String(translate(fallbackKey) || '').trim();
|
||||
}
|
||||
@ -1,2 +1,2 @@
|
||||
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
|
||||
{assign var=venix_asset_version value='2026110714' scope='global'}
|
||||
{assign var=venix_asset_version value='2026110715' scope='global'}
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
const presentationUrl = new URL(
|
||||
'../public/cloud/operation-presentation.js',
|
||||
import.meta.url,
|
||||
);
|
||||
const { operationTitle } = await import(
|
||||
`${presentationUrl.href}?test=${Date.now()}`
|
||||
);
|
||||
|
||||
const translations = {
|
||||
'common.operation.kind.service_compensation': 'Instance Availability Compensation',
|
||||
'common.operation.action.shutdown': 'Shut Down',
|
||||
'common.operation.kind.firewall_apply': 'Apply Firewall',
|
||||
'common.operation.setting.hostname': 'Change Hostname',
|
||||
'common.operation.setting.password': 'Reset root Password',
|
||||
'common.operation.list_separator': ', ',
|
||||
'common.tasks.fallback_title': 'Background Task',
|
||||
'instance_detail.operation_log.category.instance': 'Instance Operation',
|
||||
};
|
||||
const text = key => translations[key] || key;
|
||||
|
||||
for (const [entry, expected] of [
|
||||
[{
|
||||
kind: 'service_compensation', kind_label: '实例可用时间补偿',
|
||||
operation_copy_keys: ['common.operation.kind.service_compensation'],
|
||||
}, 'Instance Availability Compensation'],
|
||||
[{
|
||||
kind: 'action', action: 'shutdown', kind_label: '关机', action_label: '关机',
|
||||
operation_copy_keys: ['common.operation.action.shutdown'],
|
||||
}, 'Shut Down'],
|
||||
[{
|
||||
kind: 'firewall_apply', kind_label: '应用防火墙',
|
||||
operation_copy_keys: ['common.operation.kind.firewall_apply'],
|
||||
}, 'Apply Firewall'],
|
||||
]) {
|
||||
const actual = operationTitle(
|
||||
entry,
|
||||
text,
|
||||
'instance_detail.operation_log.category.instance',
|
||||
);
|
||||
assert.equal(actual, expected);
|
||||
assert.doesNotMatch(actual, /[\u3400-\u9fff]/u);
|
||||
}
|
||||
|
||||
assert.equal(operationTitle({
|
||||
kind: 'instance_settings', kind_label: '修改主机名、重置 root 密码',
|
||||
operation_copy_keys: [
|
||||
'common.operation.setting.hostname',
|
||||
'common.operation.setting.password',
|
||||
],
|
||||
}, text, 'instance_detail.operation_log.category.instance'),
|
||||
'Change Hostname, Reset root Password');
|
||||
|
||||
assert.equal(operationTitle({
|
||||
kind: 'unknown_internal_job', kind_label: '未知内部任务',
|
||||
}, text, 'common.tasks.fallback_title'), 'Background Task');
|
||||
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
require dirname(__DIR__) . '/vendor/autoload.php';
|
||||
|
||||
use App\Services\Cloud\CloudOperationCatalog;
|
||||
use App\Services\UserCopy\UserCopyManifest;
|
||||
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$sources = CloudOperationCatalog::copySources();
|
||||
$assert(count($sources) === count(CloudOperationCatalog::kinds()) + 9,
|
||||
'Operation copy sources do not cover every kind, power action, setting field and separator.');
|
||||
|
||||
$entries = array_column(UserCopyManifest::load()['entries'], null, 'key');
|
||||
foreach ($sources as $copyKey => $source) {
|
||||
$entry = $entries[$copyKey] ?? null;
|
||||
$assert(is_array($entry)
|
||||
&& ($entry['source'] ?? null) === $source
|
||||
&& ($entry['scope'] ?? null) === 'common'
|
||||
&& ($entry['page'] ?? null) === 'cloud.detail'
|
||||
&& ($entry['editor_surface'] ?? null) === 'admin',
|
||||
'Operation copy entry is absent or has the wrong runtime/editor owner: '
|
||||
. $copyKey);
|
||||
}
|
||||
|
||||
foreach (array_keys(CloudOperationCatalog::kinds()) as $kind) {
|
||||
$keys = CloudOperationCatalog::copyKeys($kind);
|
||||
$assert($keys !== [] && isset($entries[$keys[0]]),
|
||||
'Operation kind lacks a stable UserCopy key: ' . $kind);
|
||||
}
|
||||
|
||||
$assert(
|
||||
CloudOperationCatalog::copyKeys('action', 'shutdown')
|
||||
=== ['common.operation.action.shutdown']
|
||||
&& CloudOperationCatalog::copyKeys('instance_settings', null, [
|
||||
'hostname', 'password',
|
||||
]) === [
|
||||
'common.operation.setting.hostname',
|
||||
'common.operation.setting.password',
|
||||
]
|
||||
&& CloudOperationCatalog::copyKeys('unknown_internal_job') === [],
|
||||
'Operation presentation keys do not fail closed around stable catalog codes.'
|
||||
);
|
||||
Loading…
Reference in New Issue