mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 00:08:52 +00:00
Language switch: a live switch redraws the chat messages, and the tool-summary lines and the code label are said in the chosen language (GUI-VIS-1117 finding 2)
The chat's Message and the Markdown preview slices are memo() components that change no prop on a language switch, so they kept the words of the
language before until a reload (German with Japanese code labels and "thought for", Hebrew with Korean). They now read the language from the store.
The host writes an activity group's line in English from its counts ("Ran a command, edited a file"), and the saved chat keeps it, so that line and the
"code" label were English in every language. lib/group-line.ts reads the line back into its parts and says each in the person's language (ten languages,
make-guic-locales.py; Spanish, French, Portuguese and Russian join with a small letter after the first part, Japanese and Chinese with their own comma).
An unknown sentence stays as written. English is unchanged. New texts are drafts until the coordinator confirms them.
Test: tests/language-switch-live.test.mjs (memo components read the language; the line in all ten languages; no cache across switches).
This commit is contained in:
1 parent
252fc0c09d
commit
a26b822caf
16 files changed
+421
-11
No files matched your search
@@ -590,6 +590,148 @@ add(en="7d",
|
||||
ko="7일",
|
||||
fr="7 j",
|
||||
he="7 ימים")
|
||||
# activity group lines (the host writes them in English from its counts; the page reads them back, lib/group-line.ts) and the code label of a code block: ten languages
|
||||
# (GUI-VIS-1117 finding 2). English = the host's own sentences, unchanged; translations are lane drafts for review.
|
||||
add(en='Ran {0} commands',
|
||||
zh='已运行 {0} 条命令',
|
||||
ja='コマンドを {0} 件実行しました',
|
||||
de='{0} Befehle ausgeführt',
|
||||
es='{0} comandos ejecutados',
|
||||
ru='Выполнено команд: {0}',
|
||||
pt='{0} comandos executados',
|
||||
ko='명령 {0}개 실행함',
|
||||
fr='{0} commandes exécutées',
|
||||
he='הורצו {0} פקודות')
|
||||
add(en='Read {0} files',
|
||||
zh='已读取 {0} 个文件',
|
||||
ja='{0} 個のファイルを読み込みました',
|
||||
de='{0} Dateien gelesen',
|
||||
es='{0} archivos leídos',
|
||||
ru='Прочитано файлов: {0}',
|
||||
pt='{0} arquivos lidos',
|
||||
ko='파일 {0}개 읽음',
|
||||
fr='{0} fichiers lus',
|
||||
he='נקראו {0} קבצים')
|
||||
add(en='Edited a file',
|
||||
zh='已编辑文件',
|
||||
ja='ファイルを編集しました',
|
||||
de='Datei bearbeitet',
|
||||
es='Archivo editado',
|
||||
ru='Файл изменён',
|
||||
pt='Arquivo editado',
|
||||
ko='파일 편집함',
|
||||
fr='Fichier modifié',
|
||||
he='נערך קובץ')
|
||||
add(en='Searched a search',
|
||||
zh='已搜索一次',
|
||||
ja='検索を1回実行しました',
|
||||
de='Einmal gesucht',
|
||||
es='Una búsqueda hecha',
|
||||
ru='Выполнен поиск',
|
||||
pt='Uma pesquisa feita',
|
||||
ko='검색 1회 실행함',
|
||||
fr='Une recherche effectuée',
|
||||
he='בוצע חיפוש')
|
||||
add(en='Searched {0} searches',
|
||||
zh='已搜索 {0} 次',
|
||||
ja='検索を {0} 回実行しました',
|
||||
de='{0}-mal gesucht',
|
||||
es='{0} búsquedas hechas',
|
||||
ru='Выполнено поисков: {0}',
|
||||
pt='{0} pesquisas feitas',
|
||||
ko='검색 {0}회 실행함',
|
||||
fr='{0} recherches effectuées',
|
||||
he='בוצעו {0} חיפושים')
|
||||
add(en='Looked up a web page',
|
||||
zh='已查阅网页',
|
||||
ja='Web ページを調べました',
|
||||
de='Webseite nachgeschlagen',
|
||||
es='Página web consultada',
|
||||
ru='Открыта веб-страница',
|
||||
pt='Página da web consultada',
|
||||
ko='웹 페이지를 조회함',
|
||||
fr='Page web consultée',
|
||||
he='נבדק דף אינטרנט')
|
||||
add(en='Looked up {0} web pages',
|
||||
zh='已查阅 {0} 个网页',
|
||||
ja='{0} 件の Web ページを調べました',
|
||||
de='{0} Webseiten nachgeschlagen',
|
||||
es='{0} páginas web consultadas',
|
||||
ru='Открыто веб-страниц: {0}',
|
||||
pt='{0} páginas da web consultadas',
|
||||
ko='웹 페이지 {0}개 조회함',
|
||||
fr='{0} pages web consultées',
|
||||
he='נבדקו {0} דפי אינטרנט')
|
||||
add(en='Used the browser for a browser step',
|
||||
zh='浏览器已执行一步',
|
||||
ja='ブラウザーで1ステップ操作しました',
|
||||
de='Browser-Schritt ausgeführt',
|
||||
es='Un paso en el navegador',
|
||||
ru='Выполнен шаг в браузере',
|
||||
pt='Um passo no navegador',
|
||||
ko='브라우저 단계 1회 실행함',
|
||||
fr='Une étape dans le navigateur',
|
||||
he='בוצע שלב בדפדפן')
|
||||
add(en='Used the browser for {0} browser steps',
|
||||
zh='浏览器已执行 {0} 步',
|
||||
ja='ブラウザーで {0} ステップ操作しました',
|
||||
de='{0} Browser-Schritte ausgeführt',
|
||||
es='{0} pasos en el navegador',
|
||||
ru='Выполнено шагов в браузере: {0}',
|
||||
pt='{0} passos no navegador',
|
||||
ko='브라우저 단계 {0}회 실행함',
|
||||
fr='{0} étapes dans le navigateur',
|
||||
he='בוצעו {0} שלבים בדפדפן')
|
||||
add(en='Started a helper',
|
||||
zh='已启动助手',
|
||||
ja='ヘルパーを起動しました',
|
||||
de='Helfer gestartet',
|
||||
es='Ayudante iniciado',
|
||||
ru='Запущен помощник',
|
||||
pt='Ajudante iniciado',
|
||||
ko='도우미를 시작함',
|
||||
fr='Auxiliaire lancé',
|
||||
he='הופעל עוזר')
|
||||
add(en='Started {0} helpers',
|
||||
zh='已启动 {0} 个助手',
|
||||
ja='{0} 個のヘルパーを起動しました',
|
||||
de='{0} Helfer gestartet',
|
||||
es='{0} ayudantes iniciados',
|
||||
ru='Запущено помощников: {0}',
|
||||
pt='{0} ajudantes iniciados',
|
||||
ko='도우미 {0}개를 시작함',
|
||||
fr='{0} auxiliaires lancés',
|
||||
he='הופעלו {0} עוזרים')
|
||||
add(en='Used a tool',
|
||||
zh='已使用工具',
|
||||
ja='ツールを使いました',
|
||||
de='Werkzeug verwendet',
|
||||
es='Herramienta usada',
|
||||
ru='Использован инструмент',
|
||||
pt='Ferramenta usada',
|
||||
ko='도구를 사용함',
|
||||
fr='Outil utilisé',
|
||||
he='נעשה שימוש בכלי')
|
||||
add(en='Used {0} tools',
|
||||
zh='已使用 {0} 个工具',
|
||||
ja='{0} 個のツールを使いました',
|
||||
de='{0} Werkzeuge verwendet',
|
||||
es='{0} herramientas usadas',
|
||||
ru='Использовано инструментов: {0}',
|
||||
pt='{0} ferramentas usadas',
|
||||
ko='도구 {0}개를 사용함',
|
||||
fr='{0} outils utilisés',
|
||||
he='נעשה שימוש ב-{0} כלים')
|
||||
add(en='code',
|
||||
zh='代码',
|
||||
ja='コード',
|
||||
de='Code',
|
||||
es='código',
|
||||
ru='код',
|
||||
pt='código',
|
||||
ko='코드',
|
||||
fr='code',
|
||||
he='קוד')
|
||||
here = APP / "src" / "locales"
|
||||
NBSP = " "
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { plainFailureText } from '../lib/plain-errors';
|
||||
import { FloatingMenu } from './FloatingMenu';
|
||||
import { CopyMenuItem } from './CopyBtn';
|
||||
import { Icon } from './ui';
|
||||
import { groupSentence } from '../lib/group-line';
|
||||
|
||||
const problem = (title: string, e: unknown) => pushToast('error', tr(title), plainFailureText(e instanceof Error ? e.message : String(e)).message);
|
||||
|
||||
@@ -111,7 +112,7 @@ export function ActivityLine({ group, sessionId, onPreview }: { group: ActivityG
|
||||
const [open, setOpen] = useState(false);
|
||||
const picture = group.files.find(f => f.kind === 'image');
|
||||
// The host's sentence may end with the numbers ("… +225 −0"): they are drawn as figures instead.
|
||||
const sentence = group.line.replace(/\s*\+\d+\s*[−-]\s*\d+\s*$/, '');
|
||||
const sentence = groupSentence(group.line.replace(/\s*\+\d+\s*[−-]\s*\d+\s*$/, ''));
|
||||
// While the run is open this is the live step: the host's own words for it when it sends them, else the line it already had.
|
||||
const live = !group.closed;
|
||||
return <><div className="act" data-open={open || undefined} data-live={live || undefined}>
|
||||
|
||||
@@ -6,15 +6,18 @@
|
||||
* - a block too large to parse, and a file above the limit, shown as plain text.
|
||||
*/
|
||||
import { memo, useEffect, useMemo, useState } from 'react';
|
||||
import { useStore } from '../lib/store';
|
||||
import { Markdown } from './Markdown';
|
||||
import { SyntaxCode } from './SyntaxCode';
|
||||
import { previewSlices, previewTier, slicesAfter, slicesAtStart, textRevision } from '../lib/preview-render';
|
||||
|
||||
const Slice = memo(function Slice({ text, plain }: { text: string; plain: boolean }) {
|
||||
useStore(s => s.language); // memo(): the code label and the buttons are drawn in the language of the moment
|
||||
return plain ? <SyntaxCode text={text}/> : <Markdown text={text}/>;
|
||||
});
|
||||
|
||||
export const PreviewMarkdown = memo(function PreviewMarkdown({ text }: { text: string }) {
|
||||
useStore(s => s.language);
|
||||
if (previewTier(text) === 'plain')
|
||||
return <SyntaxCode text={text}/>;
|
||||
return <Sliced text={text}/>;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { tr, currentLanguage } from './i18n';
|
||||
|
||||
/**
|
||||
* The host writes an activity group's line in English from its counts ("Ran 2 commands, read a file"; server/agent/deliverables.mjs groupLine) and the saved chat keeps
|
||||
* that sentence, so the page reads it back into (kind, count) and says each part in the language of the moment. A part it does not know is left as the host wrote it.
|
||||
* The English output is the same sentence as before (the strings below are the host's own words, so English is unchanged).
|
||||
*/
|
||||
const KINDS: { kind: string; verb: string; noun: [string, string]; one: string; many: string }[] = [
|
||||
{ kind: 'command', verb: 'Ran', noun: ['command', 'commands'], one: 'Ran a command', many: 'Ran {0} commands' },
|
||||
{ kind: 'read', verb: 'Read', noun: ['file', 'files'], one: 'Read a file', many: 'Read {0} files' },
|
||||
{ kind: 'edit', verb: 'Edited', noun: ['file', 'files'], one: 'Edited a file', many: 'Edited {0} files' },
|
||||
{ kind: 'search', verb: 'Searched', noun: ['search', 'searches'], one: 'Searched a search', many: 'Searched {0} searches' },
|
||||
{ kind: 'web', verb: 'Looked up', noun: ['web page', 'web pages'], one: 'Looked up a web page', many: 'Looked up {0} web pages' },
|
||||
{ kind: 'browser', verb: 'Used the browser for', noun: ['browser step', 'browser steps'], one: 'Used the browser for a browser step', many: 'Used the browser for {0} browser steps' },
|
||||
{ kind: 'helper', verb: 'Started', noun: ['helper', 'helpers'], one: 'Started a helper', many: 'Started {0} helpers' },
|
||||
{ kind: 'other', verb: 'Used', noun: ['tool', 'tools'], one: 'Used a tool', many: 'Used {0} tools' },
|
||||
];
|
||||
/** Languages whose sentence parts after the first start with a small letter, as in English ("Ran a command, read a file"). */
|
||||
const SMALL_AFTER_FIRST = new Set(['en', 'es', 'fr', 'pt', 'ru']);
|
||||
const JOIN: Record<string, string> = { ja: '\u3001', zh: '\uff0c' };
|
||||
|
||||
/** One part of the host's sentence as (phrase key, count), or null. Its first letter may be small (the parts after the first). */
|
||||
export function readPart(part: string): { one: string; many: string; n: number } | null {
|
||||
const text = part.trim();
|
||||
for (const k of KINDS) {
|
||||
const m = new RegExp('^' + k.verb.replace(/^./, c => '[' + c.toUpperCase() + c.toLowerCase() + ']') + ' (a|\\d+) (' + k.noun[0] + '|' + k.noun[1] + ')$').exec(text);
|
||||
if (m) return { one: k.one, many: k.many, n: m[1] === 'a' ? 1 : Number(m[1]) };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function groupSentence(line: string): string {
|
||||
if (!line) return line;
|
||||
const parts = line.split(', ');
|
||||
const read = parts.map(readPart);
|
||||
if (read.some(x => x === null)) return line; // a sentence this page does not know: as the host wrote it
|
||||
const language = currentLanguage();
|
||||
const out = (read as { one: string; many: string; n: number }[]).map((x, i) => {
|
||||
const said = x.n === 1 ? tr(x.one) : tr(x.many, [x.n]);
|
||||
if (i === 0) return said;
|
||||
return SMALL_AFTER_FIRST.has(language) ? said.charAt(0).toLocaleLowerCase(language) + said.slice(1) : said;
|
||||
});
|
||||
return out.join(JOIN[language] ?? ', ');
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "Ein Teil des Modells ist bereits vorhanden",
|
||||
"guic53": "Strata prüft zuerst die Dateien.",
|
||||
"guic54": "30 T",
|
||||
"guic55": "7 T"
|
||||
"guic55": "7 T",
|
||||
"guic56": "{0} Befehle ausgeführt",
|
||||
"guic57": "{0} Dateien gelesen",
|
||||
"guic58": "Datei bearbeitet",
|
||||
"guic59": "Einmal gesucht",
|
||||
"guic60": "{0}-mal gesucht",
|
||||
"guic61": "Webseite nachgeschlagen",
|
||||
"guic62": "{0} Webseiten nachgeschlagen",
|
||||
"guic63": "Browser-Schritt ausgeführt",
|
||||
"guic64": "{0} Browser-Schritte ausgeführt",
|
||||
"guic65": "Helfer gestartet",
|
||||
"guic66": "{0} Helfer gestartet",
|
||||
"guic67": "Werkzeug verwendet",
|
||||
"guic68": "{0} Werkzeuge verwendet",
|
||||
"guic69": "Code"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "Part of the model is already here",
|
||||
"guic53": "Strata checks the files first.",
|
||||
"guic54": "30d",
|
||||
"guic55": "7d"
|
||||
"guic55": "7d",
|
||||
"guic56": "Ran {0} commands",
|
||||
"guic57": "Read {0} files",
|
||||
"guic58": "Edited a file",
|
||||
"guic59": "Searched a search",
|
||||
"guic60": "Searched {0} searches",
|
||||
"guic61": "Looked up a web page",
|
||||
"guic62": "Looked up {0} web pages",
|
||||
"guic63": "Used the browser for a browser step",
|
||||
"guic64": "Used the browser for {0} browser steps",
|
||||
"guic65": "Started a helper",
|
||||
"guic66": "Started {0} helpers",
|
||||
"guic67": "Used a tool",
|
||||
"guic68": "Used {0} tools",
|
||||
"guic69": "code"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "Una parte del modelo ya está aquí",
|
||||
"guic53": "Strata comprueba primero los archivos.",
|
||||
"guic54": "30 d",
|
||||
"guic55": "7 d"
|
||||
"guic55": "7 d",
|
||||
"guic56": "{0} comandos ejecutados",
|
||||
"guic57": "{0} archivos leídos",
|
||||
"guic58": "Archivo editado",
|
||||
"guic59": "Una búsqueda hecha",
|
||||
"guic60": "{0} búsquedas hechas",
|
||||
"guic61": "Página web consultada",
|
||||
"guic62": "{0} páginas web consultadas",
|
||||
"guic63": "Un paso en el navegador",
|
||||
"guic64": "{0} pasos en el navegador",
|
||||
"guic65": "Ayudante iniciado",
|
||||
"guic66": "{0} ayudantes iniciados",
|
||||
"guic67": "Herramienta usada",
|
||||
"guic68": "{0} herramientas usadas",
|
||||
"guic69": "código"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "Une partie du modèle est déjà là",
|
||||
"guic53": "Strata vérifie d’abord les fichiers.",
|
||||
"guic54": "30 j",
|
||||
"guic55": "7 j"
|
||||
"guic55": "7 j",
|
||||
"guic56": "{0} commandes exécutées",
|
||||
"guic57": "{0} fichiers lus",
|
||||
"guic58": "Fichier modifié",
|
||||
"guic59": "Une recherche effectuée",
|
||||
"guic60": "{0} recherches effectuées",
|
||||
"guic61": "Page web consultée",
|
||||
"guic62": "{0} pages web consultées",
|
||||
"guic63": "Une étape dans le navigateur",
|
||||
"guic64": "{0} étapes dans le navigateur",
|
||||
"guic65": "Auxiliaire lancé",
|
||||
"guic66": "{0} auxiliaires lancés",
|
||||
"guic67": "Outil utilisé",
|
||||
"guic68": "{0} outils utilisés",
|
||||
"guic69": "code"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "חלק מהמודל כבר כאן",
|
||||
"guic53": "Strata בודק קודם את הקבצים.",
|
||||
"guic54": "30 ימים",
|
||||
"guic55": "7 ימים"
|
||||
"guic55": "7 ימים",
|
||||
"guic56": "הורצו {0} פקודות",
|
||||
"guic57": "נקראו {0} קבצים",
|
||||
"guic58": "נערך קובץ",
|
||||
"guic59": "בוצע חיפוש",
|
||||
"guic60": "בוצעו {0} חיפושים",
|
||||
"guic61": "נבדק דף אינטרנט",
|
||||
"guic62": "נבדקו {0} דפי אינטרנט",
|
||||
"guic63": "בוצע שלב בדפדפן",
|
||||
"guic64": "בוצעו {0} שלבים בדפדפן",
|
||||
"guic65": "הופעל עוזר",
|
||||
"guic66": "הופעלו {0} עוזרים",
|
||||
"guic67": "נעשה שימוש בכלי",
|
||||
"guic68": "נעשה שימוש ב-{0} כלים",
|
||||
"guic69": "קוד"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "モデルの一部はすでにあります",
|
||||
"guic53": "Strata は最初にファイルを確認します。",
|
||||
"guic54": "30日",
|
||||
"guic55": "7日"
|
||||
"guic55": "7日",
|
||||
"guic56": "コマンドを {0} 件実行しました",
|
||||
"guic57": "{0} 個のファイルを読み込みました",
|
||||
"guic58": "ファイルを編集しました",
|
||||
"guic59": "検索を1回実行しました",
|
||||
"guic60": "検索を {0} 回実行しました",
|
||||
"guic61": "Web ページを調べました",
|
||||
"guic62": "{0} 件の Web ページを調べました",
|
||||
"guic63": "ブラウザーで1ステップ操作しました",
|
||||
"guic64": "ブラウザーで {0} ステップ操作しました",
|
||||
"guic65": "ヘルパーを起動しました",
|
||||
"guic66": "{0} 個のヘルパーを起動しました",
|
||||
"guic67": "ツールを使いました",
|
||||
"guic68": "{0} 個のツールを使いました",
|
||||
"guic69": "コード"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "모델의 일부가 이미 있습니다",
|
||||
"guic53": "Strata가 먼저 파일을 확인합니다.",
|
||||
"guic54": "30일",
|
||||
"guic55": "7일"
|
||||
"guic55": "7일",
|
||||
"guic56": "명령 {0}개 실행함",
|
||||
"guic57": "파일 {0}개 읽음",
|
||||
"guic58": "파일 편집함",
|
||||
"guic59": "검색 1회 실행함",
|
||||
"guic60": "검색 {0}회 실행함",
|
||||
"guic61": "웹 페이지를 조회함",
|
||||
"guic62": "웹 페이지 {0}개 조회함",
|
||||
"guic63": "브라우저 단계 1회 실행함",
|
||||
"guic64": "브라우저 단계 {0}회 실행함",
|
||||
"guic65": "도우미를 시작함",
|
||||
"guic66": "도우미 {0}개를 시작함",
|
||||
"guic67": "도구를 사용함",
|
||||
"guic68": "도구 {0}개를 사용함",
|
||||
"guic69": "코드"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "Parte do modelo já está aqui",
|
||||
"guic53": "O Strata verifica os arquivos primeiro.",
|
||||
"guic54": "30 d",
|
||||
"guic55": "7 d"
|
||||
"guic55": "7 d",
|
||||
"guic56": "{0} comandos executados",
|
||||
"guic57": "{0} arquivos lidos",
|
||||
"guic58": "Arquivo editado",
|
||||
"guic59": "Uma pesquisa feita",
|
||||
"guic60": "{0} pesquisas feitas",
|
||||
"guic61": "Página da web consultada",
|
||||
"guic62": "{0} páginas da web consultadas",
|
||||
"guic63": "Um passo no navegador",
|
||||
"guic64": "{0} passos no navegador",
|
||||
"guic65": "Ajudante iniciado",
|
||||
"guic66": "{0} ajudantes iniciados",
|
||||
"guic67": "Ferramenta usada",
|
||||
"guic68": "{0} ferramentas usadas",
|
||||
"guic69": "código"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "Часть модели уже здесь",
|
||||
"guic53": "Strata сначала проверит файлы.",
|
||||
"guic54": "30 дн.",
|
||||
"guic55": "7 дн."
|
||||
"guic55": "7 дн.",
|
||||
"guic56": "Выполнено команд: {0}",
|
||||
"guic57": "Прочитано файлов: {0}",
|
||||
"guic58": "Файл изменён",
|
||||
"guic59": "Выполнен поиск",
|
||||
"guic60": "Выполнено поисков: {0}",
|
||||
"guic61": "Открыта веб-страница",
|
||||
"guic62": "Открыто веб-страниц: {0}",
|
||||
"guic63": "Выполнен шаг в браузере",
|
||||
"guic64": "Выполнено шагов в браузере: {0}",
|
||||
"guic65": "Запущен помощник",
|
||||
"guic66": "Запущено помощников: {0}",
|
||||
"guic67": "Использован инструмент",
|
||||
"guic68": "Использовано инструментов: {0}",
|
||||
"guic69": "код"
|
||||
}
|
||||
@@ -53,5 +53,19 @@
|
||||
"guic52": "模型的一部分已经在这里",
|
||||
"guic53": "Strata 会先检查文件。",
|
||||
"guic54": "30天",
|
||||
"guic55": "7天"
|
||||
"guic55": "7天",
|
||||
"guic56": "已运行 {0} 条命令",
|
||||
"guic57": "已读取 {0} 个文件",
|
||||
"guic58": "已编辑文件",
|
||||
"guic59": "已搜索一次",
|
||||
"guic60": "已搜索 {0} 次",
|
||||
"guic61": "已查阅网页",
|
||||
"guic62": "已查阅 {0} 个网页",
|
||||
"guic63": "浏览器已执行一步",
|
||||
"guic64": "浏览器已执行 {0} 步",
|
||||
"guic65": "已启动助手",
|
||||
"guic66": "已启动 {0} 个助手",
|
||||
"guic67": "已使用工具",
|
||||
"guic68": "已使用 {0} 个工具",
|
||||
"guic69": "代码"
|
||||
}
|
||||
@@ -744,6 +744,7 @@ function MessageView({ message: m, isLast, onEditPrompt, onPreview, onClosePrevi
|
||||
timeSkipReal?: boolean;
|
||||
timeSkipRun?: TimeSkipRun;
|
||||
}) {
|
||||
useStore(s => s.language); // memo(): a live language switch changes no prop, so the message subscribes to it and draws its words again
|
||||
const streaming = useStore(s => s.streaming);
|
||||
const activeSession = useStore(s => s.activeSession);
|
||||
const hostLive = useStore(s => s.connection !== 'offline');
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// Visual walkthrough (GUI-VIS-1117, finding 2): after a live language switch, parts of the chat kept the words of the language before (German with Japanese,
|
||||
// Hebrew with Korean) until a reload, and the tool-summary line of a turn ("Ran a command, edited a file") and the code label were English in every language.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { build } from 'esbuild';
|
||||
|
||||
const LANGS = ['zh', 'ja', 'de', 'es', 'ru', 'pt', 'ko', 'fr', 'he'];
|
||||
const built = await build({ stdin: { contents: "export * from './src/lib/i18n'; export * from './src/lib/group-line';", resolveDir: process.cwd() }, bundle: true, write: false, format: 'esm', platform: 'node', loader: { '.json': 'json' } });
|
||||
const { tr, setTranslationLanguage, loadCatalog, groupSentence } = await import(`data:text/javascript;base64,${Buffer.from(built.outputFiles[0].text).toString('base64')}`);
|
||||
for (const l of LANGS) await loadCatalog(l);
|
||||
|
||||
const walk = dir => readdirSync(dir).flatMap(name => { const p = join(dir, name); return statSync(p).isDirectory() ? walk(p) : [p]; });
|
||||
|
||||
test('every memoised component that draws translated words subscribes to the language', () => {
|
||||
const missing = [];
|
||||
for (const file of walk('src').filter(f => /\.tsx$/.test(f))) {
|
||||
const text = readFileSync(file, 'utf8').replace(/\r\n/g, '\n');
|
||||
if (!/\bmemo\(/.test(text) || !/\btr\(/.test(text)) continue;
|
||||
// each memo() component body (or the one the memo wraps) must read the language from the store, else a live switch changes no prop and nothing redraws
|
||||
const bodies = [...text.matchAll(/memo\((?:function\s+\w+|\w+)/g)].length;
|
||||
const reads = [...text.matchAll(/useStore\(\s*\(?s\)?\s*=>\s*s\.language\s*\)/g)].length;
|
||||
if (reads < bodies) missing.push(`${file}: ${bodies} memo(), ${reads} language reads`);
|
||||
}
|
||||
assert.deepEqual(missing, []);
|
||||
});
|
||||
|
||||
test('the English line of a turn is the sentence the host wrote', async () => {
|
||||
await setTranslationLanguage('en');
|
||||
for (const line of ['Ran a command', 'Ran a command, edited a file', 'Ran 2 commands, read a file, edited 3 files', 'Searched 4 searches, looked up a web page', 'Used the browser for 2 browser steps', 'Started a helper'])
|
||||
assert.equal(groupSentence(line), line);
|
||||
assert.equal(groupSentence('A sentence the page does not know'), 'A sentence the page does not know');
|
||||
assert.equal(groupSentence(''), '');
|
||||
});
|
||||
|
||||
test('the line is said in the language of the moment and holds no word of the host\'s English in any language', async () => {
|
||||
for (const l of LANGS) {
|
||||
await setTranslationLanguage(l);
|
||||
for (const line of ['Read a file', 'Ran a command, edited a file', 'Ran 2 commands, read 3 files, edited a file', 'Searched a search, looked up 2 web pages', 'Used 2 tools']) {
|
||||
const said = groupSentence(line);
|
||||
assert.notEqual(said, line, `${l}: "${line}" is still English`);
|
||||
assert.ok(!/\{\d+\}/.test(said), `${l}: raw slot in ${said}`);
|
||||
assert.ok(!/\b(Ran|Read|Edited|Searched|Looked up|Started|Used)\b/.test(said), `${l}: English verb left in ${said}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('a switch from one language to another changes the sentence at once (no cache of the old one)', async () => {
|
||||
await setTranslationLanguage('ja');
|
||||
const ja = groupSentence('Ran a command, edited a file');
|
||||
await setTranslationLanguage('de');
|
||||
const de = groupSentence('Ran a command, edited a file');
|
||||
await setTranslationLanguage('he');
|
||||
const he = groupSentence('Ran a command, edited a file');
|
||||
assert.equal(new Set([ja, de, he]).size, 3);
|
||||
assert.equal(de, 'Befehl ausgeführt, Datei bearbeitet');
|
||||
assert.match(ja, /コマンド/);
|
||||
assert.match(he, /[-]/);
|
||||
});
|
||||
|
||||
test('the Spanish, French, Portuguese and Russian lines join with a small letter after the first part, Japanese and Chinese with their own comma', async () => {
|
||||
await setTranslationLanguage('es');
|
||||
assert.equal(groupSentence('Ran a command, edited a file'), 'Comando ejecutado, archivo editado');
|
||||
await setTranslationLanguage('fr');
|
||||
assert.equal(groupSentence('Ran a command, edited a file'), 'Commande exécutée, fichier modifié');
|
||||
await setTranslationLanguage('ja');
|
||||
assert.ok(groupSentence('Ran a command, edited a file').includes('、'));
|
||||
await setTranslationLanguage('zh');
|
||||
assert.ok(groupSentence('Ran a command, edited a file').includes(','));
|
||||
});
|
||||
|
||||
test('the code label has a word of its own in every language', async () => {
|
||||
for (const l of LANGS) {
|
||||
await setTranslationLanguage(l);
|
||||
assert.ok(tr('code').length > 0);
|
||||
if (l === 'he' || l === 'ja' || l === 'ko' || l === 'zh' || l === 'ru') assert.notEqual(tr('code'), 'code', l);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user