Skip to content

Commit 700b4dc

Browse files
committed
fix(service-storage): storage test connection copy covers all eleven platform languages
Adds zh-Hant, ar, fr, pt-BR, ru, de and ko to the storage/test copy table, reads the caller's code through platformLocaleTagOf (aliases and table tags) and then shorter subtags, and pins that every key carries every language. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Utp6CaWLG2RrgKub5oRNjC
1 parent 554ca28 commit 700b4dc

3 files changed

Lines changed: 130 additions & 19 deletions

File tree

‎.changeset/30335-storage-test-message-locale.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ fix(service-storage): Setup → Storage → Test connection answers in the calle
77
Clause-②: no
88
Metadata-protocol: none
99

10-
The `storage/test` settings action writes its `message` in the language the settings action route hands its handler as `locale` (`Accept-Language`, else `?locale`), the same source the mail test notice reads. It covers the sentences the product writes: the success sentence (which still names the adapter), the refusal when the probe read back is not the one written, and the refusal for S3 settings missing a bucket or a region. An adapter's own error text stays verbatim: alone in English, as before; in another language behind a lead-in saying the connection test failed. Locales: `en`, `zh-CN`, `ja-JP`, `es-ES`; an absent locale, or one with no copy, is answered in English exactly as before. `ok`, `severity`, the probe and its cleanup, and the operator log lines are unchanged.
10+
The `storage/test` settings action writes its `message` in the language the settings action route hands its handler as `locale` (`Accept-Language`, else `?locale`), the same source the mail test notice reads. It covers the sentences the product writes: the success sentence (which still names the adapter), the refusal when the probe read back is not the one written, and the refusal for S3 settings missing a bucket or a region. An adapter's own error text stays verbatim: alone in English, as before; in another language behind a lead-in saying the connection test failed. Every language on the platform locale table is served (`en`, `zh-CN`, `zh-Hant`, `es-ES`, `ar`, `fr`, `pt-BR`, `ru`, `de`, `ja-JP`, `ko`), the caller's code read through `platformLocaleTagOf` and then shortened one subtag at a time; an absent locale, or one the table does not name, is answered in English exactly as before. `ok`, `severity`, the probe and its cleanup, and the operator log lines are unchanged.

‎packages/services/service-storage/src/storage-test-copy.ts‎

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,31 @@
22

33
/**
44
* [#30335] The sentences Setup → Storage → 测试连接 (`storage/test`) answers
5-
* with, one entry per locale this package's `translations/` serves.
5+
* with, one entry per language on the platform locale table.
66
*
77
* The console prints the action's `message` as the toast, bare, so the
88
* sentence is the administrator's whole answer. The settings action route
99
* hands the handler the caller's display language (`Accept-Language`, else
1010
* `?locale`) as the input's `locale`; an absent locale, or one with no entry
1111
* here, is answered in English, the sentence every caller got before.
1212
*
13+
* The table carries every language on the platform locale table
14+
* (`@objectstack/spec/system` `PLATFORM_LOCALES`). The four entries this package
15+
* served first keep their keys (`zh-CN`, `ja-JP`, `es-ES`); the caller's code is
16+
* read through the table's own reader, `platformLocaleTagOf`, so a stored
17+
* alias (`zh-TW`, `pt`, `en-US`) and a table tag (`zh-Hans`, `ja`) both find
18+
* their entry. A code the table does not name is shortened one subtag at a
19+
* time (RFC 4647 lookup: `fr-CA` → `fr`, `zh-Hant-TW` → `zh-Hant`); nothing
20+
* left ⇒ English.
21+
*
1322
* Only the sentences the product writes live here. An adapter's own error
1423
* text (the S3 SDK's, the file system's) is passed through verbatim: in
1524
* English on its own, as it always was; in another language behind a lead-in
1625
* that says the connection test failed, so the reader knows what the
1726
* untranslated part is. The operator log lines stay English.
1827
*/
1928

20-
import { resolveLocale } from '@objectstack/core';
29+
import { platformLocaleTagOf, type PlatformLocaleTag } from '@objectstack/spec/system';
2130

2231
/** The English refusal for S3 settings missing a bucket or a region. */
2332
export const S3_SETTINGS_INCOMPLETE_MESSAGE =
@@ -47,7 +56,11 @@ export interface StorageTestCopy {
4756
failed(reason: string): string;
4857
}
4958

50-
export const STORAGE_TEST_COPY: Record<'en' | 'zh-CN' | 'ja-JP' | 'es-ES', StorageTestCopy> = {
59+
/** The table's keys: the platform locale table's languages, the first four under their older codes. */
60+
export type StorageTestCopyLocale =
61+
'en' | 'zh-CN' | 'zh-Hant' | 'es-ES' | 'ar' | 'fr' | 'pt-BR' | 'ru' | 'de' | 'ja-JP' | 'ko';
62+
63+
export const STORAGE_TEST_COPY: Record<StorageTestCopyLocale, StorageTestCopy> = {
5164
en: {
5265
succeeded: (adapter) => `Storage round-trip succeeded (adapter=${adapter}).`,
5366
downloadMismatch: 'Probe download did not match upload.',
@@ -60,24 +73,89 @@ export const STORAGE_TEST_COPY: Record<'en' | 'zh-CN' | 'ja-JP' | 'es-ES', Stora
6073
s3SettingsIncomplete: 'S3 适配器需要填写存储桶(s3_bucket)和区域(s3_region)。',
6174
failed: (reason) => `存储连接测试失败:${reason}`,
6275
},
76+
'zh-Hant': {
77+
succeeded: (adapter) => `儲存空間連線測試成功(轉接器:${adapter})。`,
78+
downloadMismatch: '探測檔案下載後的內容與上傳的不一致。',
79+
s3SettingsIncomplete: 'S3 轉接器需要填寫儲存貯體(s3_bucket)和區域(s3_region)。',
80+
failed: (reason) => `儲存空間連線測試失敗:${reason}`,
81+
},
6382
'ja-JP': {
6483
succeeded: (adapter) => `ストレージの接続テストに成功しました(アダプター: ${adapter})。`,
6584
downloadMismatch: 'プローブファイルのダウンロード内容がアップロードした内容と一致しません。',
6685
s3SettingsIncomplete: 'S3 アダプターにはバケット(s3_bucket)とリージョン(s3_region)の指定が必要です。',
6786
failed: (reason) => `ストレージの接続テストに失敗しました: ${reason}`,
6887
},
88+
ko: {
89+
succeeded: (adapter) => `스토리지 연결 테스트에 성공했습니다(어댑터: ${adapter}).`,
90+
downloadMismatch: '다운로드한 테스트 파일이 업로드한 파일과 일치하지 않습니다.',
91+
s3SettingsIncomplete: 'S3 어댑터에는 버킷(s3_bucket)과 리전(s3_region)이 필요합니다.',
92+
failed: (reason) => `스토리지 연결 테스트에 실패했습니다: ${reason}`,
93+
},
6994
'es-ES': {
7095
succeeded: (adapter) => `La prueba de conexión del almacenamiento se ha completado correctamente (adaptador: ${adapter}).`,
7196
downloadMismatch: 'El archivo de prueba descargado no coincide con el que se subió.',
7297
s3SettingsIncomplete: 'El adaptador S3 necesita un bucket (s3_bucket) y una región (s3_region).',
7398
failed: (reason) => `La prueba de conexión del almacenamiento ha fallado: ${reason}`,
7499
},
100+
ar: {
101+
succeeded: (adapter) => `نجح اختبار الاتصال بالتخزين (المحوّل: ${adapter}).`,
102+
downloadMismatch: 'محتوى ملف الاختبار الذي تم تنزيله لا يطابق الملف الذي تم رفعه.',
103+
s3SettingsIncomplete: 'يتطلب محوّل S3 تحديد الحاوية (s3_bucket) والمنطقة (s3_region).',
104+
failed: (reason) => `فشل اختبار الاتصال بالتخزين: ${reason}`,
105+
},
106+
fr: {
107+
succeeded: (adapter) => `Le test de connexion au stockage a réussi (adaptateur : ${adapter}).`,
108+
downloadMismatch: 'Le fichier de test téléchargé ne correspond pas à celui qui a été envoyé.',
109+
s3SettingsIncomplete: 'L’adaptateur S3 nécessite un bucket (s3_bucket) et une région (s3_region).',
110+
failed: (reason) => `Le test de connexion au stockage a échoué : ${reason}`,
111+
},
112+
'pt-BR': {
113+
succeeded: (adapter) => `O teste de conexão com o armazenamento foi concluído com sucesso (adaptador: ${adapter}).`,
114+
downloadMismatch: 'O arquivo de teste baixado não corresponde ao que foi enviado.',
115+
s3SettingsIncomplete: 'O adaptador S3 exige um bucket (s3_bucket) e uma região (s3_region).',
116+
failed: (reason) => `O teste de conexão com o armazenamento falhou: ${reason}`,
117+
},
118+
ru: {
119+
succeeded: (adapter) => `Проверка подключения к хранилищу прошла успешно (адаптер: ${adapter}).`,
120+
downloadMismatch: 'Скачанный тестовый файл не совпадает с загруженным.',
121+
s3SettingsIncomplete: 'Для адаптера S3 нужно указать бакет (s3_bucket) и регион (s3_region).',
122+
failed: (reason) => `Проверка подключения к хранилищу не удалась: ${reason}`,
123+
},
124+
de: {
125+
succeeded: (adapter) => `Der Verbindungstest zum Speicher war erfolgreich (Adapter: ${adapter}).`,
126+
downloadMismatch: 'Die heruntergeladene Testdatei stimmt nicht mit der hochgeladenen überein.',
127+
s3SettingsIncomplete: 'Der S3-Adapter benötigt einen Bucket (s3_bucket) und eine Region (s3_region).',
128+
failed: (reason) => `Der Verbindungstest zum Speicher ist fehlgeschlagen: ${reason}`,
129+
},
130+
};
131+
132+
/** Each platform locale table tag → the key that serves it. */
133+
const KEY_BY_TABLE_TAG: Record<PlatformLocaleTag, StorageTestCopyLocale> = {
134+
en: 'en',
135+
'zh-Hans': 'zh-CN',
136+
'zh-Hant': 'zh-Hant',
137+
es: 'es-ES',
138+
ar: 'ar',
139+
fr: 'fr',
140+
'pt-BR': 'pt-BR',
141+
ru: 'ru',
142+
de: 'de',
143+
ja: 'ja-JP',
144+
ko: 'ko',
75145
};
76146

77-
const COPY_LOCALES = Object.keys(STORAGE_TEST_COPY);
147+
/** The key that serves a caller's code, or `undefined` (⇒ English). */
148+
export function storageTestCopyLocaleOf(locale: string | undefined): StorageTestCopyLocale | undefined {
149+
if (!locale) return undefined;
150+
const subtags = locale.split('-');
151+
for (let n = subtags.length; n > 0; n -= 1) {
152+
const tag = platformLocaleTagOf(subtags.slice(0, n).join('-'));
153+
if (tag) return KEY_BY_TABLE_TAG[tag];
154+
}
155+
return undefined;
156+
}
78157

79-
/** The copy for a caller's locale: exact, then by language, else English. */
158+
/** The copy for a caller's locale; English when the code names no language on the table. */
80159
export function storageTestCopy(locale: string | undefined): StorageTestCopy {
81-
const picked = locale ? resolveLocale(locale, COPY_LOCALES) : undefined;
82-
return STORAGE_TEST_COPY[(picked ?? 'en') as keyof typeof STORAGE_TEST_COPY];
160+
return STORAGE_TEST_COPY[storageTestCopyLocaleOf(locale) ?? 'en'];
83161
}

‎packages/services/service-storage/src/storage-test-locale.test.ts‎

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import { tmpdir } from 'node:os';
2020
import { join } from 'node:path';
2121
import { StorageServicePlugin } from './storage-service-plugin.js';
2222
import { LocalStorageAdapter } from './local-storage-adapter.js';
23-
import { storageTestCopy, STORAGE_TEST_COPY } from './storage-test-copy.js';
23+
import { PLATFORM_LOCALE_TAGS } from '@objectstack/spec/system';
24+
import { storageTestCopy, storageTestCopyLocaleOf, STORAGE_TEST_COPY } from './storage-test-copy.js';
2425

2526
function makeCtx() {
2627
const services = new Map<string, unknown>();
@@ -102,7 +103,7 @@ describe('[#30335] storage/test answers in the caller\'s language', () => {
102103
it('no locale, or one with no copy: English, exactly as an older settings host gets it', async () => {
103104
const { root, settings } = await bootPlugin();
104105
const values = { adapter: 'local', local_root: root };
105-
for (const input of [{ values }, { values, locale: 'fr-FR' }, { values, locale: '' }]) {
106+
for (const input of [{ values }, { values, locale: 'tr-TR' }, { values, locale: '' }]) {
106107
const result = await settings.run(input);
107108
expect(result.ok).toBe(true);
108109
expect(result.severity).toBe('info');
@@ -164,15 +165,47 @@ describe('[#30335] storage/test answers in the caller\'s language', () => {
164165
});
165166

166167
describe('[#30335] the storage/test copy table', () => {
167-
it('serves every locale the package\'s translations serve, each with every sentence', () => {
168-
expect(Object.keys(STORAGE_TEST_COPY).sort()).toEqual(['en', 'es-ES', 'ja-JP', 'zh-CN']);
169-
for (const locale of Object.keys(STORAGE_TEST_COPY)) {
170-
const copy = storageTestCopy(locale);
171-
expect(copy.succeeded('s3')).toContain('s3');
172-
expect(copy.downloadMismatch.length).toBeGreaterThan(0);
173-
expect(copy.s3SettingsIncomplete).toContain('s3_bucket');
174-
expect(copy.s3SettingsIncomplete).toContain('s3_region');
175-
expect(copy.failed('EACCES')).toContain('EACCES');
168+
const KEYS = ['ar', 'de', 'en', 'es-ES', 'fr', 'ja-JP', 'ko', 'pt-BR', 'ru', 'zh-CN', 'zh-Hant'];
169+
170+
it('carries all 11 languages of the platform locale table, each with every sentence', () => {
171+
expect(Object.keys(STORAGE_TEST_COPY).sort()).toEqual(KEYS);
172+
// Every table tag finds its own entry (none falls through to English).
173+
expect(PLATFORM_LOCALE_TAGS).toHaveLength(11);
174+
for (const tag of PLATFORM_LOCALE_TAGS) {
175+
expect(storageTestCopyLocaleOf(tag), tag).toBeDefined();
176+
}
177+
const en = STORAGE_TEST_COPY.en;
178+
for (const key of KEYS) {
179+
const copy = STORAGE_TEST_COPY[key as keyof typeof STORAGE_TEST_COPY];
180+
expect(Object.keys(copy).sort(), key).toEqual(['downloadMismatch', 'failed', 's3SettingsIncomplete', 'succeeded']);
181+
// Placeholders survive verbatim; the two setting keys are named as written.
182+
expect(copy.succeeded('ADAPTER_X'), key).toContain('ADAPTER_X');
183+
expect(copy.failed('REASON_Y'), key).toContain('REASON_Y');
184+
expect(copy.s3SettingsIncomplete, key).toContain('s3_bucket');
185+
expect(copy.s3SettingsIncomplete, key).toContain('s3_region');
186+
expect(copy.downloadMismatch.length, key).toBeGreaterThan(0);
187+
if (key !== 'en') {
188+
// A real translation, not the English sentence copied in.
189+
expect(copy.succeeded('local'), key).not.toBe(en.succeeded('local'));
190+
expect(copy.downloadMismatch, key).not.toBe(en.downloadMismatch);
191+
expect(copy.s3SettingsIncomplete, key).not.toBe(en.s3SettingsIncomplete);
192+
expect(copy.failed('x'), key).not.toBe(en.failed('x'));
193+
}
194+
}
195+
});
196+
197+
it('reads a caller\'s code through the platform table: aliases, table tags, then shorter subtags', () => {
198+
const cases: Array<[string | undefined, string | undefined]> = [
199+
['zh-CN', 'zh-CN'], ['zh', 'zh-CN'], ['zh-Hans', 'zh-CN'], ['zh-Hans-CN', 'zh-CN'],
200+
['zh-TW', 'zh-Hant'], ['zh-HK', 'zh-Hant'], ['zh-Hant', 'zh-Hant'], ['zh-Hant-TW', 'zh-Hant'],
201+
['ja', 'ja-JP'], ['ja-JP', 'ja-JP'], ['es', 'es-ES'], ['es-MX', 'es-ES'],
202+
['pt', 'pt-BR'], ['pt-BR', 'pt-BR'], ['fr-FR', 'fr'], ['de-DE', 'de'], ['ko-KR', 'ko'],
203+
['ru', 'ru'], ['ar-SA', 'ar'], ['en-US', 'en'], ['EN-gb', 'en'],
204+
['xx-YY', undefined], ['', undefined], [undefined, undefined],
205+
];
206+
for (const [code, key] of cases) {
207+
expect(storageTestCopyLocaleOf(code), String(code)).toBe(key);
176208
}
209+
expect(storageTestCopy('xx-YY')).toBe(STORAGE_TEST_COPY.en);
177210
});
178211
});

0 commit comments

Comments
 (0)