diff --git a/MANIFEST.in b/MANIFEST.in index e6dd481f..d96b9db6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,6 +4,7 @@ include __init__.py README.zh-CN.md include NOTICE THIRD_PARTY_NOTICES.md CONTRIBUTING.md SECURITY.md CITATION.cff recursive-include example_workflows *.json recursive-include web *.js *.css +recursive-include web/locales *.json include web/vendor/three/LICENSE include web/assets/*.svg web/assets/*.png web/assets/*.webp recursive-include web/assets/image *.webp diff --git a/docs/I18N.md b/docs/I18N.md new file mode 100644 index 00000000..8c05182d --- /dev/null +++ b/docs/I18N.md @@ -0,0 +1,48 @@ +# Frontend internationalization (incremental migration) + +FreeVideo historically embeds pairs of English and Chinese strings directly in +JavaScript. This change proposes a dependency-free catalog architecture that +keeps those existing translations working during migration. + +## Locale selection +Use Settings > Appearance > Interface language, or the existing +`freevideo_lang` query parameter: `en`, `zh` or `pt-BR`. The explicit +selection takes priority over the browser locale. Unsupported locales fall back +to English. Changing the setting reloads the UI using the existing FreeVideo +mechanism; it does not restart the server. + +## Adding UI text + +1. Add a stable, contextual key to `web/locales/en.json`, `zh.json` and + `pt-BR.json`. Keep the same keys across the catalogs. +2. Import `translateKey` from `web/i18n.js`. For example: + ```js + import { translateKey } from './i18n.js'; + const label = translateKey('ui.generate_video'); + const eta = translateKey('progress.estimate_minutes', undefined, {minutes: 18}); + ``` +3. Run `node scripts/build_locales.mjs` to regenerate the bundled ES module. + The generated module is checked in to avoid runtime JSON requests or + dependency on import attributes in older browsers. +4. Run `node scripts/build_locales.mjs --check` and + `node --test scripts/test_i18n.mjs scripts/test_freevideo_entry.mjs`. + +Existing bilingual calls use the transitional `translatePair(en, zh, chinese)` +adapter. It preserves existing English/Chinese wording and uses known catalog +entries for Portuguese, falling back to English for untranslated strings. +New code should use stable keys instead. Keep labels separate from protocol +identifiers, prompts, model names, persisted settings, and workflow data. + +## Scope and limits + +This first contribution centralizes locale selection and translation helpers, +migrates view navigation and primary video generation labels to keys, and +provides an initial Brazilian Portuguese catalog. Settings and common controls +can use the legacy bridge as their strings are migrated. Long tutorial and +release content, specialized editor controls, messages and more complex +pluralization still need dedicated migration and native-speaker review. This is +not a claim of complete Portuguese coverage. The Task Manager extension is +intentionally not part of this branch. + +Browser acceptance testing of all locales, narrow layouts and live generation +continues to be required before upstream merge. Development used AI assistance. diff --git a/scripts/build_locales.mjs b/scripts/build_locales.mjs new file mode 100644 index 00000000..719d21ad --- /dev/null +++ b/scripts/build_locales.mjs @@ -0,0 +1,19 @@ +// Keep JSON as the editable source of truth. Emit a synchronous browser ES module, +// avoiding a runtime network request or JSON import-attribute browser dependency. +import fs from 'node:fs'; +import {fileURLToPath} from 'node:url'; +const root = new URL('../web/locales/', import.meta.url); +const languages = ['en', 'zh', 'pt-BR']; +const catalogs = Object.fromEntries(languages.map(lang => [lang, JSON.parse(fs.readFileSync(new URL(lang+'.json', root), 'utf8'))])); +const keys = Object.keys(catalogs.en).sort(); +for (const lang of languages) { + for (const [key, value] of Object.entries(catalogs[lang])) { + if (!Object.hasOwn(catalogs.en, key) || typeof value !== 'string' || !value.trim()) throw new Error(lang+': invalid entry '+key); + } + for (const key of keys) if (!Object.hasOwn(catalogs[lang], key)) throw new Error(lang+': missing '+key); +} +const source = '// Generated by scripts/build_locales.mjs. Edit locales/*.json instead.\nexport const catalogs = '+JSON.stringify(catalogs, null, 2)+';\n'; +const output = fileURLToPath(new URL('catalogs.js', root)); +if (process.argv.includes('--check')) { + if (fs.readFileSync(output, 'utf8').replace(/\r\n/g,'\n') !== source) throw new Error('Locale bundle is stale; run node scripts/build_locales.mjs'); +} else fs.writeFileSync(output, source); diff --git a/scripts/test_freevideo_entry.mjs b/scripts/test_freevideo_entry.mjs index 61f889bf..512ca4d9 100644 --- a/scripts/test_freevideo_entry.mjs +++ b/scripts/test_freevideo_entry.mjs @@ -134,6 +134,7 @@ test('main browser entry registers both views and preserves node hooks', async t source = source.replace("from './fv_player.js'", `from '${new URL('../web/fv_player.js', import.meta.url).href}'`); source = source.replace("from './fv_select.js'", `from '${new URL('../web/fv_select.js', import.meta.url).href}'`); source = source.replace("from './tip_words.js'", `from '${new URL('../web/tip_words.js', import.meta.url).href}'`); + source = source.replace("from './i18n.js'", `from '${new URL('../web/i18n.js', import.meta.url).href}'`); source = source.replace("from './cut_tip.js'", `from '${new URL('../web/cut_tip.js', import.meta.url).href}'`); source = source.replace("from './middle_frames.js'", `from '${new URL('../web/middle_frames.js', import.meta.url).href}'`); source = source.replace("from './workflow_drafts.js'", `from '${new URL('../web/workflow_drafts.js', import.meta.url).href}'`); diff --git a/scripts/test_i18n.mjs b/scripts/test_i18n.mjs new file mode 100644 index 00000000..5e5899ad --- /dev/null +++ b/scripts/test_i18n.mjs @@ -0,0 +1,60 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {readFileSync} from 'node:fs'; +import {execFileSync} from 'node:child_process'; +import {fileURLToPath} from 'node:url'; +import { resolveLocale, translateKey, translatePair, nextLocale, SUPPORTED_LOCALES } from '../web/i18n.js'; +import { catalogs } from '../web/locales/catalogs.js'; + +test('locale priority and regional aliases', () => { + assert.equal(resolveLocale('?freevideo_lang=pt-BR', 'zh-CN'), 'pt-BR'); + assert.equal(resolveLocale('?freevideo_lang=en', 'pt-BR'), 'en'); + assert.equal(resolveLocale('?freevideo_lang=zh', 'en-US'), 'zh'); + assert.equal(resolveLocale('', 'pt-br'), 'pt-BR'); + assert.equal(resolveLocale('', 'zh-TW'), 'zh'); + assert.equal(resolveLocale('', 'fr-FR'), 'en'); + assert.equal(resolveLocale('?freevideo_lang=invalid', 'en-US'), 'en'); +}); +test('catalogs agree with source and every translation is nonempty', () => { + const keySet = Object.keys(catalogs.en).sort(); + assert.ok(keySet.length >= 140); + for (const language of SUPPORTED_LOCALES) { + assert.deepEqual(Object.keys(catalogs[language]).sort(), keySet); + assert.deepEqual(catalogs[language], JSON.parse(readFileSync(new URL('../web/locales/'+language+'.json', import.meta.url), 'utf8'))); + for (const key of keySet) assert.ok(catalogs[language][key].trim()); + } + execFileSync(process.execPath, [fileURLToPath(new URL('./build_locales.mjs', import.meta.url)), '--check']); +}); +test('stable keys preserve native English and Chinese with Brazilian Portuguese', () => { + assert.equal(translateKey('nav.create', 'en'), 'Create'); + assert.equal(translateKey('nav.create', 'zh'), '创作面板'); + assert.equal(translateKey('nav.create', 'pt-BR'), 'Criar'); + assert.equal(translateKey('ui.generate_video', 'pt-BR'), 'Gerar vídeo'); + assert.equal(translateKey('ui.generate_video', 'unsupported'), 'Generate video'); + assert.equal(translateKey('missing.key', 'pt-BR'), 'missing.key'); + assert.equal(translateKey('toString', 'pt-BR'), 'toString'); + assert.equal(translateKey('progress.estimate_minutes', 'pt-BR', {minutes: 18}), 'Cerca de 18 min'); +}); +test('legacy bridge preserves supplied English and Chinese and falls back for unknown Portuguese copy', () => { + const old = globalThis.location; + try { + globalThis.location = {search: '?freevideo_lang=en'}; + assert.equal(translatePair('Settings','自定义',false), 'Settings'); + globalThis.location.search = '?freevideo_lang=zh'; + assert.equal(translatePair('Settings','自定义',true), '自定义'); + globalThis.location.search = '?freevideo_lang=pt-BR'; + assert.equal(translatePair('Settings','设置',false), 'Configurações'); + assert.equal(translatePair('About 18 min','约 18 分钟',false), 'Cerca de 18 min'); + assert.equal(translatePair('Generating 42%','正在生成 42%',false), 'Gerando 42%'); + assert.equal(translatePair('Light','浅色',false), 'Claro'); + assert.equal(translatePair('Light','光线',false), 'Luz'); + assert.equal(translatePair('Light','轻量',false), 'Leve'); + assert.equal(translatePair('Untranslated original','原文',false), 'Untranslated original'); + assert.equal(translatePair('Settings','设置',true), '设置'); + } finally { if (old === undefined) delete globalThis.location; else globalThis.location=old; } +}); +test('all three locales are reachable from command palette', () => { + assert.equal(nextLocale('en'), 'zh'); + assert.equal(nextLocale('zh'), 'pt-BR'); + assert.equal(nextLocale('pt-BR'), 'en'); +}); diff --git a/web/autopilot.js b/web/autopilot.js index b8f2c5b4..acb138a5 100644 --- a/web/autopilot.js +++ b/web/autopilot.js @@ -1,3 +1,4 @@ +import { currentLocale, translatePair } from './i18n.js'; import {createLanAccess} from './lan_access.js'; // The Agent's own page, beside the studio and the editing view: the card that connects one, then the conversation with it. import { api } from '../../scripts/api.js'; @@ -16,11 +17,8 @@ import { keepViewSwitchPlace } from './view_switch_place.js'; import { tip } from './autopilot_tips.js'; import { agentPost } from './agent_session.js'; -const languageOverride = typeof location !== 'undefined' - ? new URLSearchParams(location.search).get('freevideo_lang') : null; -const cn = languageOverride === 'zh' || (languageOverride !== 'en' - && String(navigator.language || '').toLowerCase().startsWith('zh')); -const t = (en, zh) => cn ? zh : en; +const cn = currentLocale() === 'zh'; +const t = (en, zh) => translatePair(en, zh, cn); const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; }; let current = null, kept = null; diff --git a/web/comfy_templates.js b/web/comfy_templates.js index 3f581f7f..ec3aa01f 100644 --- a/web/comfy_templates.js +++ b/web/comfy_templates.js @@ -1,9 +1,8 @@ +import { currentLocale } from './i18n.js'; // ComfyUI's own Templates window, shown over the Nodes view: FreeVideo says its search box and its first category in the // interface language (ComfyUI's Chinese file reads the search box as "搜索占位符", and the category name is not translated), // and comfy_templates.css brings the window into the light theme. The window is added to the page body when it opens. -const query = new URLSearchParams(globalThis.location?.search || ''); -const asked = query.get('freevideo_lang'); -export const chinese = asked === 'zh' || (asked !== 'en' && String(globalThis.navigator?.language || '').toLowerCase().startsWith('zh')); +export const chinese = currentLocale() === 'zh'; // English text of a ComfyUI-made label -> the Chinese FreeVideo shows in its place. export const LABELS = {Popular: '热门'}; diff --git a/web/compatibility.js b/web/compatibility.js index 871b72d8..31a033fd 100644 --- a/web/compatibility.js +++ b/web/compatibility.js @@ -1,3 +1,4 @@ +import { currentLocale, translatePair } from './i18n.js'; import { api } from '../../scripts/api.js'; import './fv_select.js'; import './glass/library.js'; @@ -9,11 +10,8 @@ const saveFailure = (error, tt) => { const text = userMessage(error, tt, tt('Cou const readFailure = (error, tt) => { const text = userMessage(error, tt, tt('Could not read the setting. Try again.', '没能读取设置,请重试。')); return text === String(error?.message ?? '').trim() ? tt('The setting could not be read: ', '无法读取设置:') + text : text; }; -const languageOverride = typeof location !== 'undefined' - ? new URLSearchParams(location.search).get('freevideo_lang') : null; -const cn = languageOverride === 'zh' || (languageOverride !== 'en' - && String(navigator.language || '').toLowerCase().startsWith('zh')); -const t = (en, zh) => cn ? zh : en; +const cn = currentLocale() === 'zh'; +const t = (en, zh) => translatePair(en, zh, cn); const unavailable = () => t('Device information is unavailable; compatibility settings are off.', '无法获取设备信息,兼容性设置已关闭。'); let current; const element = (tag, text) => { const node = document.createElement(tag); if (text) node.textContent = text; return node; }; diff --git a/web/context_menu.js b/web/context_menu.js index b9782ccf..3f3f4dd4 100644 --- a/web/context_menu.js +++ b/web/context_menu.js @@ -1,3 +1,4 @@ +import { currentLocale, translatePair } from './i18n.js'; // The one right-click menu of every FreeVideo view, and the small pieces the command layer shares (language, // icons, how a shortcut is written). The library, the image view and the editor build their menus with it: // attachContextMenu(element, event => items | null) right click, Shift+F10, the menu key, a long press on touch @@ -10,12 +11,10 @@ import { isolateDialogKeys, listenDialogKey } from './dialog_keys.js'; const browser = typeof document !== 'undefined'; -const query = browser ? new URLSearchParams(globalThis.location?.search || '') : new URLSearchParams(); -const forced = query.get('freevideo_lang'); -export const CN = forced === 'zh' || (forced !== 'en' && String(globalThis.navigator?.language || '').toLowerCase().startsWith('zh')); -export const t = (en, zh) => CN ? zh : en; +export const CN = currentLocale() === 'zh'; +export const t = (en, zh) => translatePair(en, zh, CN); // [en, zh] pairs, plain strings and functions returning either all read the same way. -export const words = (value, cn = CN) => typeof value === 'function' ? words(value(), cn) : Array.isArray(value) ? String(value[cn ? 1 : 0] ?? value[0] ?? '') : String(value ?? ''); +export const words = (value, cn) => typeof value === 'function' ? words(value(), cn) : Array.isArray(value) ? String((cn === undefined ? translatePair(value[0], value[1] ?? value[0]) : value[cn ? 1 : 0]) ?? value[0] ?? '') : String(value ?? ''); export const MAC = /Mac|iPhone|iPad/.test(globalThis.navigator?.platform || globalThis.navigator?.userAgent || ''); // The compatibility view (Settings → 兼容界面, stored as freevideo.glass = solid): solid panels, fewer animations, // and nothing plays until asked. It counts as reduced motion everywhere. diff --git a/web/editor.js b/web/editor.js index 945c5aee..28557f62 100644 --- a/web/editor.js +++ b/web/editor.js @@ -1,3 +1,4 @@ +import { translatePair } from './i18n.js'; import './has_mirror.js'; import {createLanAccess} from './lan_access.js'; import {createEditorText} from './editor_text.js'; @@ -244,7 +245,7 @@ export function openEditor({api, app, from = null, panel = {}, components: given } // The same language as the top bar and the other views, read once when the page opened (the app later drops the // address's query, so reading it again when the editor opened fell back to the browser's language). - const t = (en, zh) => CN ? zh : en; + const t = (en, zh) => translatePair(en, zh, CN); const returnFocus = document.activeElement; const even = value => Math.max(2, Math.floor(value / 2) * 2); // A new edit opens with an empty second sound track, where music is made. diff --git a/web/first_run_guide.js b/web/first_run_guide.js index 005dcd2d..50550c1e 100644 --- a/web/first_run_guide.js +++ b/web/first_run_guide.js @@ -1,3 +1,4 @@ +import { translatePair } from './i18n.js'; import {SHOWCASE_TEXT, showcaseChapter, loadShowcaseImage} from './entry_showcase.js'; import './glass/library.js'; import {openAnchor} from './feature_tour_layer.js'; @@ -159,7 +160,7 @@ const ROW_ICONS = {flag: 'M4 13.5V3M4 3.5h7.5l-1.5 2.5 1.5 2.5H4', play: 'M5 3.2 const rowIcon = name => { const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); svg.setAttribute('viewBox', '0 0 16 16'); svg.setAttribute('aria-hidden', 'true'); const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); path.setAttribute('d', ROW_ICONS[name]); svg.append(path); return svg; }; export function createGuideReplayEntry({dialog, cn, api, openWorkspace, replay = replayInFront}) { - const text = key => REPLAY_TEXT[key][cn ? 1 : 0], t = (en, zh) => cn ? zh : en; + const text = key => REPLAY_TEXT[key][cn ? 1 : 0], t = (en, zh) => translatePair(en, zh, cn); const tipped = (node, name, use) => { node.dataset.fvTipName = name; node.dataset.fvTipUse = use; return node; }; const section = el('section', null, 'fv-guide-replay'), row = el('div', null, 'fv-guide-replay-row'), rows = el('div', null, 'fv-guide-rows'); const line = (icon, name, small, control) => { const item = el('div', null, 'fv-guide-row'), words = el('span'); words.append(el('b', name), el('small', small)); item.append(rowIcon(icon), words, control); return item; }; @@ -256,7 +257,7 @@ export function guideTarget(dialog, chapter, targets = {}) { } export function createFirstRunGuide({dialog, api, cn, isBusy = () => false, group = 'studio', targets = {}, onShowcaseTry = null}) { - const t = (en, zh) => cn ? zh : en; + const t = (en, zh) => translatePair(en, zh, cn); const automatic = !attempted.has(group), editor = group === 'editor'; const chapters = chaptersFor(group); if (!document.querySelector('link[data-fv-first-run-guide]')) { diff --git a/web/freevideo.js b/web/freevideo.js index 4d2d98fb..1eb8634d 100644 --- a/web/freevideo.js +++ b/web/freevideo.js @@ -1,3 +1,4 @@ +import { currentLocale, translatePair } from './i18n.js'; import { setTip } from './tip_words.js'; import { cutTip } from './cut_tip.js'; import './has_mirror.js'; @@ -48,11 +49,8 @@ import { createPlayBar } from './fv_player.js'; import { userMessage } from './user_message.js'; import { AUDIO_USE, usesOriginal, checkOriginal, checkedLength, failureText, multipleText, createUseSwitch, originalBlocked, stuckText, liftBlock } from './audio_original.js'; -const languageOverride = typeof location !== 'undefined' - ? new URLSearchParams(location.search).get('freevideo_lang') : null; -const cn = languageOverride === 'zh' || (languageOverride !== 'en' - && String(navigator.language || '').toLowerCase().startsWith('zh')); -const text = (en, zh) => cn ? zh : en; +const cn = currentLocale() === 'zh'; +const text = (en, zh) => translatePair(en, zh, cn); const style = document.createElement("style"); style.textContent = ` .fv-panel{box-sizing:border-box;width:100%;height:100%;padding:16px;background:var(--fv-card);color:var(--fv-ink);border:1px solid var(--fv-border);border-radius:var(--fv-r-md,12px);font:13px/1.6 var(--fv-font);overflow:auto;color-scheme:dark} diff --git a/web/health.js b/web/health.js index 52d1b54f..f7b0afae 100644 --- a/web/health.js +++ b/web/health.js @@ -1,3 +1,4 @@ +import { currentLocale, translatePair } from './i18n.js'; // Checks that FreeVideo's page loaded completely and says what is wrong when // it did not: which file, why, and what to do. It imports nothing at load and // styles itself inline, so it still runs when every other FreeVideo file fails. @@ -7,9 +8,8 @@ let extensionUI = null, errorUI = null; const base = new URL('./', import.meta.url); const query = new URLSearchParams(location.search); -const language = query.get('freevideo_lang'); -const cn = language === 'zh' || (language !== 'en' && String(navigator.language || '').toLowerCase().startsWith('zh')); -const t = (en, zh) => cn ? zh : en; +const cn = currentLocale() === 'zh'; +const t = (en, zh) => translatePair(en, zh, cn); // launcher.js removes this flag during setup; read it before that. const launchVisit = query.get('freevideo') === 'launch'; // Every script this folder ships; a test keeps the list in step with web/*.js. diff --git a/web/i18n.js b/web/i18n.js new file mode 100644 index 00000000..a0141c11 --- /dev/null +++ b/web/i18n.js @@ -0,0 +1,44 @@ +import { catalogs } from './locales/catalogs.js'; + +// A single locale negotiation policy, shared by the native views. +// Keep English as fallback and the existing URL as the explicit override. +export const SUPPORTED_LOCALES = Object.freeze(['en','zh','pt-BR']); +function normalize(value) { + const language = String(value || '').toLowerCase(); + return language === 'en' || language.startsWith('en-') ? 'en' + : language === 'zh' || language.startsWith('zh-') ? 'zh' + : language === 'pt' || language.startsWith('pt-') ? 'pt-BR' : null; +} +export function resolveLocale(search = globalThis.location?.search || '', browserLanguage = globalThis.navigator?.language || '') { + return normalize(new URLSearchParams(search).get('freevideo_lang')) || normalize(browserLanguage) || 'en'; +} +export const currentLocale = () => resolveLocale(); +export function translateKey(key, locale = currentLocale(), values = {}) { + const language = normalize(locale) || 'en'; + const value = (Object.hasOwn(catalogs[language], key) ? catalogs[language][key] : undefined) + ?? (Object.hasOwn(catalogs.en, key) ? catalogs.en[key] : undefined) ?? key; + return value.replace(/\{(\w+)\}/g, (match, name) => Object.hasOwn(values, name) ? String(values[name]) : match); +} +// Transitional adapter: preserve the exact English/Chinese text in the original call, +// including contextual/dynamic messages. Untranslated Portuguese strings fall back to English. +const aliases = new Map(Object.entries(catalogs.en).filter(([key]) => key.startsWith('ui.') || key.startsWith('nav.')).map(([key, english]) => [english, key])); +export function translatePair(en, zh, chinese = currentLocale() === 'zh') { + if (chinese) return zh; + if (currentLocale() !== 'pt-BR') return en; + if (en === 'Light') { + const key = zh === '浅色' ? 'theme.light' : zh === '光线' ? 'ui.light' : 'quality.light'; + return translateKey(key, 'pt-BR'); + } + const key = aliases.get(en); + if (key) return translateKey(key, 'pt-BR'); + if (typeof en === 'string') { + const estimate = /^About (\d+) min$/.exec(en); + const generating = /^Generating (\d+)%$/.exec(en); + if (estimate) return translateKey('progress.estimate_minutes', 'pt-BR', {minutes: estimate[1]}); + if (generating) return translateKey('progress.generating_percent', 'pt-BR', {percent: generating[1]}); + } + return en; +} +export function nextLocale(locale = currentLocale()) { + return SUPPORTED_LOCALES[(SUPPORTED_LOCALES.indexOf(locale)+1)%SUPPORTED_LOCALES.length]; +} diff --git a/web/image_library.js b/web/image_library.js index a1d7f398..c4beab8d 100644 --- a/web/image_library.js +++ b/web/image_library.js @@ -1,12 +1,12 @@ +import { currentLocale, translatePair } from './i18n.js'; // Pictures made in the image view live in the asset library as one-picture cards of kind "image": saved when a // generation succeeds, offered again wherever a reference picture is added. import { agentGet, agentPost, agentSend } from './agent_session.js'; import { uploadMedia } from './media_upload.js'; import { listenDialogKey } from './dialog_keys.js'; -const languageOverride = typeof location !== 'undefined' ? new URLSearchParams(location.search).get('freevideo_lang') : null; -const cn = languageOverride === 'zh' || (languageOverride !== 'en' && String(navigator.language || '').toLowerCase().startsWith('zh')); -const t = (en, zh) => cn ? zh : en; +const cn = currentLocale() === 'zh'; +const t = (en, zh) => translatePair(en, zh, cn); const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; }; const LIMIT = 200; const css = document.createElement('link'); css.rel = 'stylesheet'; css.href = new URL('./image_library.css', import.meta.url).href; document.head.append(css); diff --git a/web/image_view_ui.js b/web/image_view_ui.js index 753669a4..4f3e8c1f 100644 --- a/web/image_view_ui.js +++ b/web/image_view_ui.js @@ -1,9 +1,9 @@ +import { currentLocale, translatePair } from './i18n.js'; import { listenDialogKey } from './dialog_keys.js'; // Small pieces every part of the picture page builds with: elements, line icons, buttons, and the hover // description (name, one line of purpose, shortcut) that the shell's tooltip reads from data-fv-tip-*. -const languageOverride = typeof location !== 'undefined' ? new URLSearchParams(location.search).get('freevideo_lang') : null; -export const cn = languageOverride === 'zh' || (languageOverride !== 'en' && typeof navigator !== 'undefined' && String(navigator.language || '').toLowerCase().startsWith('zh')); -export const t = (en, zh) => cn ? zh : en; +export const cn = currentLocale() === 'zh'; +export const t = (en, zh) => translatePair(en, zh, cn); export const el = (tag, cls, text) => { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; }; diff --git a/web/locales/catalogs.js b/web/locales/catalogs.js new file mode 100644 index 00000000..060f526d --- /dev/null +++ b/web/locales/catalogs.js @@ -0,0 +1,438 @@ +// Generated by scripts/build_locales.mjs. Edit locales/*.json instead. +export const catalogs = { + "en": { + "nav.create": "Create", + "nav.images": "Images", + "nav.nodes": "Nodes", + "nav.edit": "Edit", + "nav.autopilot": "Autopilot", + "ui.tasks": "Tasks", + "ui.creations": "Creations", + "ui.settings": "Settings", + "ui.ready": "Ready", + "ui.generating": "Generating", + "ui.queued": "Queued", + "ui.waiting": "Waiting", + "ui.cancel": "Cancel", + "ui.media": "Media", + "ui.light": "Light", + "ui.medium": "Medium", + "ui.high": "High", + "ui.enhance": "Enhance", + "ui.generate_video": "Generate video", + "ui.generate_preview": "Generate preview", + "ui.download_video": "Download video", + "ui.download_picture": "Download picture", + "ui.download": "Download", + "ui.reuse_settings": "Reuse settings", + "ui.filled_in": "Filled in", + "ui.undo": "Undo", + "ui.extend": "Extend", + "ui.share": "Share", + "ui.regenerate": "Regenerate", + "ui.preview": "Preview", + "ui.search": "Search", + "ui.models": "Models", + "ui.downloads": "Downloads", + "ui.generation": "Generation", + "ui.appearance": "Appearance", + "ui.assistant": "Assistant", + "ui.storage": "Storage", + "ui.page_check": "Page check", + "ui.advanced": "Advanced", + "ui.version_updates": "Version & updates", + "ui.getting_started": "Getting started", + "ui.look": "Look", + "ui.theme": "Theme", + "ui.dark": "Dark", + "ui.dark_panels_best_for_pictures": "Dark panels, best for pictures", + "ui.light_panels": "Light panels", + "ui.applies_at_once_to_every_view": "Applies at once to every view", + "ui.compatibility_view": "Compatibility view", + "ui.solid_panels_fewer_animations_no_autoplay": "Solid panels, fewer animations, no autoplay", + "ui.top_bar": "Top bar", + "ui.show_this_computer_in_the_status": "Show this computer in the status", + "ui.graphics_memory_and_temperature_in_the_top_bar": "Graphics memory and temperature in the top bar", + "ui.language": "Language", + "ui.interface_language": "Interface language", + "ui.changing_the_language_reloads_the_page_generations_keep_running": "Changing the language reloads the page; generations keep running.", + "ui.reload_now": "Reload now", + "ui.this_computer": "This computer", + "ui.temperature": "Temperature", + "ui.disk_free": "Disk free", + "ui.temporary_files": "Temporary files", + "ui.freevideo_keeps": "FreeVideo keeps", + "ui.search_settings": "Search settings", + "ui.no_setting_matches": "No setting matches", + "nav.label": "FreeVideo view", + "ui.freevideo_settings": "FreeVideo settings", + "ui.settings_pages": "Settings pages", + "ui.freevideo_creative_workspace": "FreeVideo creative workspace", + "ui.search_works_prompts_and_actions": "Search works, prompts and actions", + "ui.reference_media": "Reference media (@)", + "ui.add_reference_pictures_video_and_sound": "Add reference pictures, video and sound", + "ui.save_the_mp4_to_this_computer": "Save the MP4 to this computer", + "ui.fill_the_creation_panel_with_these_settings": "Fill the creation panel with these settings", + "ui.tutorial": "Tutorial", + "ui.feedback": "Feedback", + "ui.version": "Version", + "ui.close": "Close", + "ui.back": "Back", + "ui.more": "More", + "ui.menu": "Menu", + "ui.run_status": "Run status", + "ui.see_running_tasks_and_notices": "See running tasks and notices", + "ui.search_and_commands": "Search and commands", + "ui.search_works_and_run_any_action": "Search works and run any action", + "ui.open_your_works_to_sort_and_manage_them": "Open your works to sort and manage them", + "ui.phone": "Phone", + "ui.open_on_a_phone_on_this_network": "Open on a phone on this network", + "ui.see_updates_and_what_is_new": "See updates and what is new", + "ui.tutorials": "Tutorials", + "ui.learn_each_feature_step_by_step": "Learn each feature step by step", + "ui.tell_us_a_problem_or_an_idea": "Tell us a problem or an idea", + "ui.models_downloads_storage_look": "Models, downloads, storage, look", + "ui.find_a_setting_by_its_name": "Find a setting by its name", + "ui.reload_the_page_in_the_chosen_language": "Reload the page in the chosen language", + "ui.show_the_interface_in_chinese": "Show the interface in Chinese", + "ui.show_the_interface_in_english": "Show the interface in English", + "ui.save": "Save", + "ui.delete": "Delete", + "ui.rename": "Rename", + "ui.copy": "Copy", + "ui.paste": "Paste", + "ui.select_all": "Select all", + "ui.clear": "Clear", + "ui.reset": "Reset", + "ui.retry": "Retry", + "ui.stop": "Stop", + "ui.continue": "Continue", + "ui.confirm": "Confirm", + "ui.apply": "Apply", + "ui.import": "Import", + "ui.export": "Export", + "ui.open": "Open", + "ui.loading": "Loading…", + "ui.done": "Done", + "ui.failed": "Failed", + "ui.image": "Image", + "ui.video": "Video", + "ui.audio": "Audio", + "ui.prompt": "Prompt", + "ui.duration": "Duration", + "ui.resolution": "Resolution", + "ui.quality": "Quality", + "ui.seed": "Seed", + "ui.width": "Width", + "ui.height": "Height", + "ui.size": "Size", + "ui.generate": "Generate", + "ui.new": "New", + "ui.more_options": "More options", + "ui.recently_deleted": "Recently deleted", + "ui.keyboard_shortcuts": "Keyboard shortcuts", + "ui.notifications": "Notifications", + "ui.check_installation": "Check installation", + "ui.install": "Install", + "ui.check_again": "Check again", + "ui.use_existing": "Use existing", + "ui.stop_setup": "Stop setup", + "ui.performance_measurement": "Performance measurement", + "ui.freevideo": "FreeVideo", + "theme.light": "Light", + "quality.light": "Light", + "progress.estimate_minutes": "About {minutes} min", + "progress.generating_percent": "Generating {percent}%", + "locale.portuguese": "Português (Brasil)" + }, + "zh": { + "nav.create": "创作面板", + "nav.images": "图像视图", + "nav.nodes": "节点视图", + "nav.edit": "剪辑视图", + "nav.autopilot": "AI 全自动", + "ui.tasks": "任务", + "ui.creations": "作品库", + "ui.settings": "设置", + "ui.ready": "就绪", + "ui.generating": "正在生成", + "ui.queued": "排队中", + "ui.waiting": "排队中", + "ui.cancel": "取消", + "ui.media": "素材", + "ui.light": "光线", + "ui.medium": "中", + "ui.high": "高", + "ui.enhance": "增强", + "ui.generate_video": "生成视频", + "ui.generate_preview": "生成预览", + "ui.download_video": "下载视频", + "ui.download_picture": "下载图片", + "ui.download": "下载", + "ui.reuse_settings": "复用设置", + "ui.filled_in": "已填入", + "ui.undo": "撤销", + "ui.extend": "拉长", + "ui.share": "分享", + "ui.regenerate": "重新生成", + "ui.preview": "预览", + "ui.search": "搜索", + "ui.models": "模型", + "ui.downloads": "下载", + "ui.generation": "生成用时", + "ui.appearance": "外观", + "ui.assistant": "助手", + "ui.storage": "存储", + "ui.page_check": "页面检查", + "ui.advanced": "高级选项", + "ui.version_updates": "版本与更新", + "ui.getting_started": "新手指引", + "ui.look": "外观", + "ui.theme": "主题", + "ui.dark": "深色", + "ui.dark_panels_best_for_pictures": "深色界面,适合看画面", + "ui.light_panels": "浅色界面", + "ui.applies_at_once_to_every_view": "立即应用到所有视图", + "ui.compatibility_view": "兼容界面", + "ui.solid_panels_fewer_animations_no_autoplay": "实体背景,减少动画,视频不自动播放", + "ui.top_bar": "顶栏", + "ui.show_this_computer_in_the_status": "在运行状态中显示本机数据", + "ui.graphics_memory_and_temperature_in_the_top_bar": "在顶栏显示显存和温度", + "ui.language": "语言", + "ui.interface_language": "界面语言", + "ui.changing_the_language_reloads_the_page_generations_keep_running": "切换语言会重新载入页面,正在进行的生成不受影响。", + "ui.reload_now": "立即重新载入", + "ui.this_computer": "本机", + "ui.temperature": "温度", + "ui.disk_free": "磁盘可用", + "ui.temporary_files": "临时文件", + "ui.freevideo_keeps": "FreeVideo 占用", + "ui.search_settings": "搜索设置", + "ui.no_setting_matches": "没有找到相关设置", + "nav.label": "FreeVideo 视图", + "ui.freevideo_settings": "FreeVideo 设置", + "ui.settings_pages": "设置页面", + "ui.freevideo_creative_workspace": "FreeVideo 创作面板", + "ui.search_works_prompts_and_actions": "搜索作品、提示词和操作", + "ui.reference_media": "引用素材(@)", + "ui.add_reference_pictures_video_and_sound": "加参考图、视频和声音", + "ui.save_the_mp4_to_this_computer": "把视频文件保存到电脑", + "ui.fill_the_creation_panel_with_these_settings": "把这次的设置填回创作面板", + "ui.tutorial": "教程", + "ui.feedback": "反馈", + "ui.version": "版本", + "ui.close": "关闭", + "ui.back": "上一步", + "ui.more": "更多", + "ui.menu": "菜单", + "ui.run_status": "运行状态", + "ui.see_running_tasks_and_notices": "看进行中的任务和通知", + "ui.search_and_commands": "搜索与命令", + "ui.search_works_and_run_any_action": "搜索作品、提示词并执行操作", + "ui.open_your_works_to_sort_and_manage_them": "打开作品库,筛选和管理", + "ui.phone": "手机", + "ui.open_on_a_phone_on_this_network": "在同一网络的手机上打开", + "ui.see_updates_and_what_is_new": "查看更新和新功能", + "ui.tutorials": "教程", + "ui.learn_each_feature_step_by_step": "一步步学会每个功能", + "ui.tell_us_a_problem_or_an_idea": "把问题或想法告诉我们", + "ui.models_downloads_storage_look": "模型、下载、存储和外观", + "ui.find_a_setting_by_its_name": "按名称查找设置", + "ui.reload_the_page_in_the_chosen_language": "以所选语言重新载入页面", + "ui.show_the_interface_in_chinese": "界面显示为中文", + "ui.show_the_interface_in_english": "界面显示为英文", + "ui.save": "保存", + "ui.delete": "删除", + "ui.rename": "改名", + "ui.copy": "复制", + "ui.paste": "粘贴", + "ui.select_all": "全选", + "ui.clear": "清空", + "ui.reset": "恢复原样", + "ui.retry": "重试", + "ui.stop": "停止", + "ui.continue": "继续", + "ui.confirm": "确认删除", + "ui.apply": "应用", + "ui.import": "导入", + "ui.export": "导出", + "ui.open": "打开", + "ui.loading": "正在读取…", + "ui.done": "完成", + "ui.failed": "失败", + "ui.image": "图片", + "ui.video": "视频", + "ui.audio": "声音", + "ui.prompt": "提示词", + "ui.duration": "时长", + "ui.resolution": "清晰度", + "ui.quality": "质量", + "ui.seed": "种子", + "ui.width": "宽度", + "ui.height": "高度", + "ui.size": "尺寸", + "ui.generate": "生成", + "ui.new": "新建", + "ui.more_options": "更多选项", + "ui.recently_deleted": "最近删除", + "ui.keyboard_shortcuts": "快捷键", + "ui.notifications": "通知", + "ui.check_installation": "检查安装", + "ui.install": "安装", + "ui.check_again": "重新检查", + "ui.use_existing": "使用已有安装", + "ui.stop_setup": "停止安装", + "ui.performance_measurement": "性能测量", + "ui.freevideo": "FreeVideo", + "theme.light": "浅色", + "quality.light": "轻量", + "progress.estimate_minutes": "约 {minutes} 分钟", + "progress.generating_percent": "生成中 {percent}%", + "locale.portuguese": "Português (Brasil)" + }, + "pt-BR": { + "nav.create": "Criar", + "nav.images": "Imagens", + "nav.nodes": "Nós", + "nav.edit": "Editar", + "nav.autopilot": "Autopilot", + "ui.tasks": "Tarefas", + "ui.creations": "Criações", + "ui.settings": "Configurações", + "ui.ready": "Pronto", + "ui.generating": "Gerando", + "ui.queued": "Na fila", + "ui.waiting": "Aguardando", + "ui.cancel": "Cancelar", + "ui.media": "Mídia", + "ui.light": "Luz", + "ui.medium": "Médio", + "ui.high": "Alto", + "ui.enhance": "Aprimorar", + "ui.generate_video": "Gerar vídeo", + "ui.generate_preview": "Gerar prévia", + "ui.download_video": "Baixar vídeo", + "ui.download_picture": "Baixar imagem", + "ui.download": "Baixar", + "ui.reuse_settings": "Reutilizar configurações", + "ui.filled_in": "Preenchido", + "ui.undo": "Desfazer", + "ui.extend": "Estender", + "ui.share": "Compartilhar", + "ui.regenerate": "Gerar novamente", + "ui.preview": "Prévia", + "ui.search": "Pesquisar", + "ui.models": "Modelos", + "ui.downloads": "Downloads", + "ui.generation": "Geração", + "ui.appearance": "Aparência", + "ui.assistant": "Assistente", + "ui.storage": "Armazenamento", + "ui.page_check": "Verificação da página", + "ui.advanced": "Avançado", + "ui.version_updates": "Versão e atualizações", + "ui.getting_started": "Primeiros passos", + "ui.look": "Aparência", + "ui.theme": "Tema", + "ui.dark": "Escuro", + "ui.dark_panels_best_for_pictures": "Painéis escuros, ideais para imagens", + "ui.light_panels": "Painéis claros", + "ui.applies_at_once_to_every_view": "Aplica-se imediatamente a todas as telas", + "ui.compatibility_view": "Modo de compatibilidade", + "ui.solid_panels_fewer_animations_no_autoplay": "Painéis sólidos, menos animações, sem reprodução automática", + "ui.top_bar": "Barra superior", + "ui.show_this_computer_in_the_status": "Mostrar este computador no status", + "ui.graphics_memory_and_temperature_in_the_top_bar": "Memória de vídeo e temperatura na barra superior", + "ui.language": "Idioma", + "ui.interface_language": "Idioma da interface", + "ui.changing_the_language_reloads_the_page_generations_keep_running": "Mudar o idioma recarrega a página; as gerações continuam.", + "ui.reload_now": "Recarregar agora", + "ui.this_computer": "Este computador", + "ui.temperature": "Temperatura", + "ui.disk_free": "Espaço livre", + "ui.temporary_files": "Arquivos temporários", + "ui.freevideo_keeps": "FreeVideo mantém", + "ui.search_settings": "Pesquisar configurações", + "ui.no_setting_matches": "Nenhuma configuração encontrada", + "nav.label": "Tela do FreeVideo", + "ui.freevideo_settings": "Configurações do FreeVideo", + "ui.settings_pages": "Páginas de configurações", + "ui.freevideo_creative_workspace": "Área de criação do FreeVideo", + "ui.search_works_prompts_and_actions": "Pesquisar criações, prompts e ações", + "ui.reference_media": "Referenciar mídia (@)", + "ui.add_reference_pictures_video_and_sound": "Adicionar imagens, vídeos e áudio de referência", + "ui.save_the_mp4_to_this_computer": "Salvar o MP4 neste computador", + "ui.fill_the_creation_panel_with_these_settings": "Preencher o painel de criação com estas configurações", + "ui.tutorial": "Tutorial", + "ui.feedback": "Feedback", + "ui.version": "Versão", + "ui.close": "Fechar", + "ui.back": "Voltar", + "ui.more": "Mais", + "ui.menu": "Menu", + "ui.run_status": "Status das tarefas", + "ui.see_running_tasks_and_notices": "Ver tarefas em execução e avisos", + "ui.search_and_commands": "Pesquisa e comandos", + "ui.search_works_and_run_any_action": "Pesquisar criações e executar ações", + "ui.open_your_works_to_sort_and_manage_them": "Abrir suas criações para organizar e gerenciar", + "ui.phone": "Celular", + "ui.open_on_a_phone_on_this_network": "Abrir em um celular nesta rede", + "ui.see_updates_and_what_is_new": "Ver atualizações e novidades", + "ui.tutorials": "Tutoriais", + "ui.learn_each_feature_step_by_step": "Aprenda cada recurso passo a passo", + "ui.tell_us_a_problem_or_an_idea": "Conte-nos um problema ou uma ideia", + "ui.models_downloads_storage_look": "Modelos, downloads, armazenamento e aparência", + "ui.find_a_setting_by_its_name": "Encontrar uma configuração pelo nome", + "ui.reload_the_page_in_the_chosen_language": "Recarregar a página no idioma escolhido", + "ui.show_the_interface_in_chinese": "Mostrar a interface em chinês", + "ui.show_the_interface_in_english": "Mostrar a interface em inglês", + "ui.save": "Salvar", + "ui.delete": "Excluir", + "ui.rename": "Renomear", + "ui.copy": "Copiar", + "ui.paste": "Colar", + "ui.select_all": "Selecionar tudo", + "ui.clear": "Limpar", + "ui.reset": "Redefinir", + "ui.retry": "Tentar novamente", + "ui.stop": "Parar", + "ui.continue": "Continuar", + "ui.confirm": "Confirmar", + "ui.apply": "Aplicar", + "ui.import": "Importar", + "ui.export": "Exportar", + "ui.open": "Abrir", + "ui.loading": "Carregando…", + "ui.done": "Concluído", + "ui.failed": "Falhou", + "ui.image": "Imagem", + "ui.video": "Vídeo", + "ui.audio": "Áudio", + "ui.prompt": "Prompt", + "ui.duration": "Duração", + "ui.resolution": "Resolução", + "ui.quality": "Qualidade", + "ui.seed": "Semente", + "ui.width": "Largura", + "ui.height": "Altura", + "ui.size": "Tamanho", + "ui.generate": "Gerar", + "ui.new": "Novo", + "ui.more_options": "Mais opções", + "ui.recently_deleted": "Excluídos recentemente", + "ui.keyboard_shortcuts": "Atalhos de teclado", + "ui.notifications": "Notificações", + "ui.check_installation": "Verificar instalação", + "ui.install": "Instalar", + "ui.check_again": "Verificar novamente", + "ui.use_existing": "Usar existentes", + "ui.stop_setup": "Interromper configuração", + "ui.performance_measurement": "Medição de desempenho", + "ui.freevideo": "FreeVideo", + "theme.light": "Claro", + "quality.light": "Leve", + "progress.estimate_minutes": "Cerca de {minutes} min", + "progress.generating_percent": "Gerando {percent}%", + "locale.portuguese": "Português (Brasil)" + } +}; diff --git a/web/locales/en.json b/web/locales/en.json new file mode 100644 index 00000000..fc6c160f --- /dev/null +++ b/web/locales/en.json @@ -0,0 +1,145 @@ +{ + "nav.create": "Create", + "nav.images": "Images", + "nav.nodes": "Nodes", + "nav.edit": "Edit", + "nav.autopilot": "Autopilot", + "ui.tasks": "Tasks", + "ui.creations": "Creations", + "ui.settings": "Settings", + "ui.ready": "Ready", + "ui.generating": "Generating", + "ui.queued": "Queued", + "ui.waiting": "Waiting", + "ui.cancel": "Cancel", + "ui.media": "Media", + "ui.light": "Light", + "ui.medium": "Medium", + "ui.high": "High", + "ui.enhance": "Enhance", + "ui.generate_video": "Generate video", + "ui.generate_preview": "Generate preview", + "ui.download_video": "Download video", + "ui.download_picture": "Download picture", + "ui.download": "Download", + "ui.reuse_settings": "Reuse settings", + "ui.filled_in": "Filled in", + "ui.undo": "Undo", + "ui.extend": "Extend", + "ui.share": "Share", + "ui.regenerate": "Regenerate", + "ui.preview": "Preview", + "ui.search": "Search", + "ui.models": "Models", + "ui.downloads": "Downloads", + "ui.generation": "Generation", + "ui.appearance": "Appearance", + "ui.assistant": "Assistant", + "ui.storage": "Storage", + "ui.page_check": "Page check", + "ui.advanced": "Advanced", + "ui.version_updates": "Version & updates", + "ui.getting_started": "Getting started", + "ui.look": "Look", + "ui.theme": "Theme", + "ui.dark": "Dark", + "ui.dark_panels_best_for_pictures": "Dark panels, best for pictures", + "ui.light_panels": "Light panels", + "ui.applies_at_once_to_every_view": "Applies at once to every view", + "ui.compatibility_view": "Compatibility view", + "ui.solid_panels_fewer_animations_no_autoplay": "Solid panels, fewer animations, no autoplay", + "ui.top_bar": "Top bar", + "ui.show_this_computer_in_the_status": "Show this computer in the status", + "ui.graphics_memory_and_temperature_in_the_top_bar": "Graphics memory and temperature in the top bar", + "ui.language": "Language", + "ui.interface_language": "Interface language", + "ui.changing_the_language_reloads_the_page_generations_keep_running": "Changing the language reloads the page; generations keep running.", + "ui.reload_now": "Reload now", + "ui.this_computer": "This computer", + "ui.temperature": "Temperature", + "ui.disk_free": "Disk free", + "ui.temporary_files": "Temporary files", + "ui.freevideo_keeps": "FreeVideo keeps", + "ui.search_settings": "Search settings", + "ui.no_setting_matches": "No setting matches", + "nav.label": "FreeVideo view", + "ui.freevideo_settings": "FreeVideo settings", + "ui.settings_pages": "Settings pages", + "ui.freevideo_creative_workspace": "FreeVideo creative workspace", + "ui.search_works_prompts_and_actions": "Search works, prompts and actions", + "ui.reference_media": "Reference media (@)", + "ui.add_reference_pictures_video_and_sound": "Add reference pictures, video and sound", + "ui.save_the_mp4_to_this_computer": "Save the MP4 to this computer", + "ui.fill_the_creation_panel_with_these_settings": "Fill the creation panel with these settings", + "ui.tutorial": "Tutorial", + "ui.feedback": "Feedback", + "ui.version": "Version", + "ui.close": "Close", + "ui.back": "Back", + "ui.more": "More", + "ui.menu": "Menu", + "ui.run_status": "Run status", + "ui.see_running_tasks_and_notices": "See running tasks and notices", + "ui.search_and_commands": "Search and commands", + "ui.search_works_and_run_any_action": "Search works and run any action", + "ui.open_your_works_to_sort_and_manage_them": "Open your works to sort and manage them", + "ui.phone": "Phone", + "ui.open_on_a_phone_on_this_network": "Open on a phone on this network", + "ui.see_updates_and_what_is_new": "See updates and what is new", + "ui.tutorials": "Tutorials", + "ui.learn_each_feature_step_by_step": "Learn each feature step by step", + "ui.tell_us_a_problem_or_an_idea": "Tell us a problem or an idea", + "ui.models_downloads_storage_look": "Models, downloads, storage, look", + "ui.find_a_setting_by_its_name": "Find a setting by its name", + "ui.reload_the_page_in_the_chosen_language": "Reload the page in the chosen language", + "ui.show_the_interface_in_chinese": "Show the interface in Chinese", + "ui.show_the_interface_in_english": "Show the interface in English", + "ui.save": "Save", + "ui.delete": "Delete", + "ui.rename": "Rename", + "ui.copy": "Copy", + "ui.paste": "Paste", + "ui.select_all": "Select all", + "ui.clear": "Clear", + "ui.reset": "Reset", + "ui.retry": "Retry", + "ui.stop": "Stop", + "ui.continue": "Continue", + "ui.confirm": "Confirm", + "ui.apply": "Apply", + "ui.import": "Import", + "ui.export": "Export", + "ui.open": "Open", + "ui.loading": "Loading…", + "ui.done": "Done", + "ui.failed": "Failed", + "ui.image": "Image", + "ui.video": "Video", + "ui.audio": "Audio", + "ui.prompt": "Prompt", + "ui.duration": "Duration", + "ui.resolution": "Resolution", + "ui.quality": "Quality", + "ui.seed": "Seed", + "ui.width": "Width", + "ui.height": "Height", + "ui.size": "Size", + "ui.generate": "Generate", + "ui.new": "New", + "ui.more_options": "More options", + "ui.recently_deleted": "Recently deleted", + "ui.keyboard_shortcuts": "Keyboard shortcuts", + "ui.notifications": "Notifications", + "ui.check_installation": "Check installation", + "ui.install": "Install", + "ui.check_again": "Check again", + "ui.use_existing": "Use existing", + "ui.stop_setup": "Stop setup", + "ui.performance_measurement": "Performance measurement", + "ui.freevideo": "FreeVideo", + "theme.light": "Light", + "quality.light": "Light", + "progress.estimate_minutes": "About {minutes} min", + "progress.generating_percent": "Generating {percent}%", + "locale.portuguese": "Português (Brasil)" +} diff --git a/web/locales/pt-BR.json b/web/locales/pt-BR.json new file mode 100644 index 00000000..5fede44e --- /dev/null +++ b/web/locales/pt-BR.json @@ -0,0 +1,145 @@ +{ + "nav.create": "Criar", + "nav.images": "Imagens", + "nav.nodes": "Nós", + "nav.edit": "Editar", + "nav.autopilot": "Autopilot", + "ui.tasks": "Tarefas", + "ui.creations": "Criações", + "ui.settings": "Configurações", + "ui.ready": "Pronto", + "ui.generating": "Gerando", + "ui.queued": "Na fila", + "ui.waiting": "Aguardando", + "ui.cancel": "Cancelar", + "ui.media": "Mídia", + "ui.light": "Luz", + "ui.medium": "Médio", + "ui.high": "Alto", + "ui.enhance": "Aprimorar", + "ui.generate_video": "Gerar vídeo", + "ui.generate_preview": "Gerar prévia", + "ui.download_video": "Baixar vídeo", + "ui.download_picture": "Baixar imagem", + "ui.download": "Baixar", + "ui.reuse_settings": "Reutilizar configurações", + "ui.filled_in": "Preenchido", + "ui.undo": "Desfazer", + "ui.extend": "Estender", + "ui.share": "Compartilhar", + "ui.regenerate": "Gerar novamente", + "ui.preview": "Prévia", + "ui.search": "Pesquisar", + "ui.models": "Modelos", + "ui.downloads": "Downloads", + "ui.generation": "Geração", + "ui.appearance": "Aparência", + "ui.assistant": "Assistente", + "ui.storage": "Armazenamento", + "ui.page_check": "Verificação da página", + "ui.advanced": "Avançado", + "ui.version_updates": "Versão e atualizações", + "ui.getting_started": "Primeiros passos", + "ui.look": "Aparência", + "ui.theme": "Tema", + "ui.dark": "Escuro", + "ui.dark_panels_best_for_pictures": "Painéis escuros, ideais para imagens", + "ui.light_panels": "Painéis claros", + "ui.applies_at_once_to_every_view": "Aplica-se imediatamente a todas as telas", + "ui.compatibility_view": "Modo de compatibilidade", + "ui.solid_panels_fewer_animations_no_autoplay": "Painéis sólidos, menos animações, sem reprodução automática", + "ui.top_bar": "Barra superior", + "ui.show_this_computer_in_the_status": "Mostrar este computador no status", + "ui.graphics_memory_and_temperature_in_the_top_bar": "Memória de vídeo e temperatura na barra superior", + "ui.language": "Idioma", + "ui.interface_language": "Idioma da interface", + "ui.changing_the_language_reloads_the_page_generations_keep_running": "Mudar o idioma recarrega a página; as gerações continuam.", + "ui.reload_now": "Recarregar agora", + "ui.this_computer": "Este computador", + "ui.temperature": "Temperatura", + "ui.disk_free": "Espaço livre", + "ui.temporary_files": "Arquivos temporários", + "ui.freevideo_keeps": "FreeVideo mantém", + "ui.search_settings": "Pesquisar configurações", + "ui.no_setting_matches": "Nenhuma configuração encontrada", + "nav.label": "Tela do FreeVideo", + "ui.freevideo_settings": "Configurações do FreeVideo", + "ui.settings_pages": "Páginas de configurações", + "ui.freevideo_creative_workspace": "Área de criação do FreeVideo", + "ui.search_works_prompts_and_actions": "Pesquisar criações, prompts e ações", + "ui.reference_media": "Referenciar mídia (@)", + "ui.add_reference_pictures_video_and_sound": "Adicionar imagens, vídeos e áudio de referência", + "ui.save_the_mp4_to_this_computer": "Salvar o MP4 neste computador", + "ui.fill_the_creation_panel_with_these_settings": "Preencher o painel de criação com estas configurações", + "ui.tutorial": "Tutorial", + "ui.feedback": "Feedback", + "ui.version": "Versão", + "ui.close": "Fechar", + "ui.back": "Voltar", + "ui.more": "Mais", + "ui.menu": "Menu", + "ui.run_status": "Status das tarefas", + "ui.see_running_tasks_and_notices": "Ver tarefas em execução e avisos", + "ui.search_and_commands": "Pesquisa e comandos", + "ui.search_works_and_run_any_action": "Pesquisar criações e executar ações", + "ui.open_your_works_to_sort_and_manage_them": "Abrir suas criações para organizar e gerenciar", + "ui.phone": "Celular", + "ui.open_on_a_phone_on_this_network": "Abrir em um celular nesta rede", + "ui.see_updates_and_what_is_new": "Ver atualizações e novidades", + "ui.tutorials": "Tutoriais", + "ui.learn_each_feature_step_by_step": "Aprenda cada recurso passo a passo", + "ui.tell_us_a_problem_or_an_idea": "Conte-nos um problema ou uma ideia", + "ui.models_downloads_storage_look": "Modelos, downloads, armazenamento e aparência", + "ui.find_a_setting_by_its_name": "Encontrar uma configuração pelo nome", + "ui.reload_the_page_in_the_chosen_language": "Recarregar a página no idioma escolhido", + "ui.show_the_interface_in_chinese": "Mostrar a interface em chinês", + "ui.show_the_interface_in_english": "Mostrar a interface em inglês", + "ui.save": "Salvar", + "ui.delete": "Excluir", + "ui.rename": "Renomear", + "ui.copy": "Copiar", + "ui.paste": "Colar", + "ui.select_all": "Selecionar tudo", + "ui.clear": "Limpar", + "ui.reset": "Redefinir", + "ui.retry": "Tentar novamente", + "ui.stop": "Parar", + "ui.continue": "Continuar", + "ui.confirm": "Confirmar", + "ui.apply": "Aplicar", + "ui.import": "Importar", + "ui.export": "Exportar", + "ui.open": "Abrir", + "ui.loading": "Carregando…", + "ui.done": "Concluído", + "ui.failed": "Falhou", + "ui.image": "Imagem", + "ui.video": "Vídeo", + "ui.audio": "Áudio", + "ui.prompt": "Prompt", + "ui.duration": "Duração", + "ui.resolution": "Resolução", + "ui.quality": "Qualidade", + "ui.seed": "Semente", + "ui.width": "Largura", + "ui.height": "Altura", + "ui.size": "Tamanho", + "ui.generate": "Gerar", + "ui.new": "Novo", + "ui.more_options": "Mais opções", + "ui.recently_deleted": "Excluídos recentemente", + "ui.keyboard_shortcuts": "Atalhos de teclado", + "ui.notifications": "Notificações", + "ui.check_installation": "Verificar instalação", + "ui.install": "Instalar", + "ui.check_again": "Verificar novamente", + "ui.use_existing": "Usar existentes", + "ui.stop_setup": "Interromper configuração", + "ui.performance_measurement": "Medição de desempenho", + "ui.freevideo": "FreeVideo", + "theme.light": "Claro", + "quality.light": "Leve", + "progress.estimate_minutes": "Cerca de {minutes} min", + "progress.generating_percent": "Gerando {percent}%", + "locale.portuguese": "Português (Brasil)" +} diff --git a/web/locales/zh.json b/web/locales/zh.json new file mode 100644 index 00000000..3e16f0fa --- /dev/null +++ b/web/locales/zh.json @@ -0,0 +1,145 @@ +{ + "nav.create": "创作面板", + "nav.images": "图像视图", + "nav.nodes": "节点视图", + "nav.edit": "剪辑视图", + "nav.autopilot": "AI 全自动", + "ui.tasks": "任务", + "ui.creations": "作品库", + "ui.settings": "设置", + "ui.ready": "就绪", + "ui.generating": "正在生成", + "ui.queued": "排队中", + "ui.waiting": "排队中", + "ui.cancel": "取消", + "ui.media": "素材", + "ui.light": "光线", + "ui.medium": "中", + "ui.high": "高", + "ui.enhance": "增强", + "ui.generate_video": "生成视频", + "ui.generate_preview": "生成预览", + "ui.download_video": "下载视频", + "ui.download_picture": "下载图片", + "ui.download": "下载", + "ui.reuse_settings": "复用设置", + "ui.filled_in": "已填入", + "ui.undo": "撤销", + "ui.extend": "拉长", + "ui.share": "分享", + "ui.regenerate": "重新生成", + "ui.preview": "预览", + "ui.search": "搜索", + "ui.models": "模型", + "ui.downloads": "下载", + "ui.generation": "生成用时", + "ui.appearance": "外观", + "ui.assistant": "助手", + "ui.storage": "存储", + "ui.page_check": "页面检查", + "ui.advanced": "高级选项", + "ui.version_updates": "版本与更新", + "ui.getting_started": "新手指引", + "ui.look": "外观", + "ui.theme": "主题", + "ui.dark": "深色", + "ui.dark_panels_best_for_pictures": "深色界面,适合看画面", + "ui.light_panels": "浅色界面", + "ui.applies_at_once_to_every_view": "立即应用到所有视图", + "ui.compatibility_view": "兼容界面", + "ui.solid_panels_fewer_animations_no_autoplay": "实体背景,减少动画,视频不自动播放", + "ui.top_bar": "顶栏", + "ui.show_this_computer_in_the_status": "在运行状态中显示本机数据", + "ui.graphics_memory_and_temperature_in_the_top_bar": "在顶栏显示显存和温度", + "ui.language": "语言", + "ui.interface_language": "界面语言", + "ui.changing_the_language_reloads_the_page_generations_keep_running": "切换语言会重新载入页面,正在进行的生成不受影响。", + "ui.reload_now": "立即重新载入", + "ui.this_computer": "本机", + "ui.temperature": "温度", + "ui.disk_free": "磁盘可用", + "ui.temporary_files": "临时文件", + "ui.freevideo_keeps": "FreeVideo 占用", + "ui.search_settings": "搜索设置", + "ui.no_setting_matches": "没有找到相关设置", + "nav.label": "FreeVideo 视图", + "ui.freevideo_settings": "FreeVideo 设置", + "ui.settings_pages": "设置页面", + "ui.freevideo_creative_workspace": "FreeVideo 创作面板", + "ui.search_works_prompts_and_actions": "搜索作品、提示词和操作", + "ui.reference_media": "引用素材(@)", + "ui.add_reference_pictures_video_and_sound": "加参考图、视频和声音", + "ui.save_the_mp4_to_this_computer": "把视频文件保存到电脑", + "ui.fill_the_creation_panel_with_these_settings": "把这次的设置填回创作面板", + "ui.tutorial": "教程", + "ui.feedback": "反馈", + "ui.version": "版本", + "ui.close": "关闭", + "ui.back": "上一步", + "ui.more": "更多", + "ui.menu": "菜单", + "ui.run_status": "运行状态", + "ui.see_running_tasks_and_notices": "看进行中的任务和通知", + "ui.search_and_commands": "搜索与命令", + "ui.search_works_and_run_any_action": "搜索作品、提示词并执行操作", + "ui.open_your_works_to_sort_and_manage_them": "打开作品库,筛选和管理", + "ui.phone": "手机", + "ui.open_on_a_phone_on_this_network": "在同一网络的手机上打开", + "ui.see_updates_and_what_is_new": "查看更新和新功能", + "ui.tutorials": "教程", + "ui.learn_each_feature_step_by_step": "一步步学会每个功能", + "ui.tell_us_a_problem_or_an_idea": "把问题或想法告诉我们", + "ui.models_downloads_storage_look": "模型、下载、存储和外观", + "ui.find_a_setting_by_its_name": "按名称查找设置", + "ui.reload_the_page_in_the_chosen_language": "以所选语言重新载入页面", + "ui.show_the_interface_in_chinese": "界面显示为中文", + "ui.show_the_interface_in_english": "界面显示为英文", + "ui.save": "保存", + "ui.delete": "删除", + "ui.rename": "改名", + "ui.copy": "复制", + "ui.paste": "粘贴", + "ui.select_all": "全选", + "ui.clear": "清空", + "ui.reset": "恢复原样", + "ui.retry": "重试", + "ui.stop": "停止", + "ui.continue": "继续", + "ui.confirm": "确认删除", + "ui.apply": "应用", + "ui.import": "导入", + "ui.export": "导出", + "ui.open": "打开", + "ui.loading": "正在读取…", + "ui.done": "完成", + "ui.failed": "失败", + "ui.image": "图片", + "ui.video": "视频", + "ui.audio": "声音", + "ui.prompt": "提示词", + "ui.duration": "时长", + "ui.resolution": "清晰度", + "ui.quality": "质量", + "ui.seed": "种子", + "ui.width": "宽度", + "ui.height": "高度", + "ui.size": "尺寸", + "ui.generate": "生成", + "ui.new": "新建", + "ui.more_options": "更多选项", + "ui.recently_deleted": "最近删除", + "ui.keyboard_shortcuts": "快捷键", + "ui.notifications": "通知", + "ui.check_installation": "检查安装", + "ui.install": "安装", + "ui.check_again": "重新检查", + "ui.use_existing": "使用已有安装", + "ui.stop_setup": "停止安装", + "ui.performance_measurement": "性能测量", + "ui.freevideo": "FreeVideo", + "theme.light": "浅色", + "quality.light": "轻量", + "progress.estimate_minutes": "约 {minutes} 分钟", + "progress.generating_percent": "生成中 {percent}%", + "locale.portuguese": "Português (Brasil)" +} diff --git a/web/media_upload.js b/web/media_upload.js index b247d2fe..f1ba6868 100644 --- a/web/media_upload.js +++ b/web/media_upload.js @@ -1,9 +1,7 @@ +import { currentLocale, translatePair } from './i18n.js'; // One media file into ComfyUI's input folder through FreeVideo's streaming upload; every upload place shares it. -const languageOverride = typeof location !== 'undefined' - ? new URLSearchParams(location.search).get('freevideo_lang') : null; -const cn = languageOverride === 'zh' || (languageOverride !== 'en' - && String(navigator.language || '').toLowerCase().startsWith('zh')); -const text = (en, zh) => cn ? zh : en; +const cn = currentLocale() === 'zh'; +const text = (en, zh) => translatePair(en, zh, cn); // The page's background loading of works (work_media.js) waits while an upload runs. const uploadRunning = active => { try { globalThis.dispatchEvent?.(new CustomEvent('freevideo-upload', {detail: {active}})); } catch { /* no page */ } }; // The server's limit; a bigger file is turned away before a byte is sent. diff --git a/web/palette.js b/web/palette.js index db3635f5..55bac82b 100644 --- a/web/palette.js +++ b/web/palette.js @@ -9,6 +9,7 @@ // reason), confirm?: [en, zh] (asks first), anyView?: true (offered from every view), run: ctx => any}. // This module also loads the rest of the command layer: shortcuts, notifications, search and the right-click menu. import { t, words, CN, MAC, glyph, keyChips, formatKeys, createLayer, addSheet } from './context_menu.js'; +import { nextLocale } from './i18n.js'; import { openShortcuts, shortcutsOpen, closeShortcuts, VIEW_NAMES } from './shortcuts.js'; import { searchEverything, searchSettled, warmSearch, fillPrompt } from './global_search.js'; import { openNotifications, latestFinished, toast, visitJob, openWork } from './notifications.js'; @@ -274,10 +275,10 @@ export function builtinCommands() { {id: 'glass.toggle', scope: 'settings', group: G.look, icon: 'layers', title: () => solidNow() ? ['Turn off compatibility view', '关闭兼容界面'] : ['Turn on compatibility view', '开启兼容界面'], use: ['For older computers', '适合较旧的电脑'], keywords: ['glass', 'blur', 'lite', 'performance', 'compatibility', 'caizhi', 'boli', 'jianrong', 'ka'], run: () => { const solid = solidNow(); if (shell()?.setGlass) shell().setGlass(solid); else document.documentElement.dataset.glass = solid ? '' : 'solid'; }}, - {id: 'language.toggle', scope: 'settings', group: G.look, icon: 'globe', title: CN ? ['English interface', '切换到英文界面'] : ['Chinese interface', '切换到中文界面'], + {id: 'language.toggle', scope: 'settings', group: G.look, icon: 'globe', title: () => ({en: ['English interface', '切换到英文界面'], zh: ['Chinese interface', '切换到中文界面'], 'pt-BR': ['Português (Brasil)', '葡萄牙语(巴西)']})[nextLocale()], use: ['Reloads the page; generations keep running', '会重新载入页面,生成不受影响'], keywords: ['language', 'english', 'chinese', 'yuyan', 'zhongwen', 'yingwen'], confirm: ['Reload the page in the other language? Generations keep running.', '重新载入页面并切换语言?正在进行的生成不受影响。'], - run: () => reloadIn(CN ? 'en' : 'zh')}, + run: () => reloadIn(nextLocale())}, {id: 'shortcuts.open', group: G.help, icon: 'keyboard', key: '?', title: ['Keyboard shortcuts', '快捷键速查'], use: ['Every shortcut of every view', '所有视图的快捷键'], keywords: ['keys', 'hotkeys', 'kuaijiejian', 'kjj'], run: () => openShortcuts()}, {id: 'tutorial.open', group: G.help, icon: 'book', title: ['Tutorial', '教程'], use: ['Learn FreeVideo step by step', '一步步学会 FreeVideo'], diff --git a/web/settings_room.js b/web/settings_room.js index 84bcdcf6..e5ef791d 100644 --- a/web/settings_room.js +++ b/web/settings_room.js @@ -6,6 +6,7 @@ // the technical parts (folders, access token, speed tables, logs) are folded away. Esc closes and gives focus back. // setup.js re-exports openSetup from here, so every caller (top bar, failure cards, palette) opens this room. import { setTip } from './tip_words.js'; +import { currentLocale, translateKey } from './i18n.js'; import { cutTip } from './cut_tip.js'; import { api } from "../../scripts/api.js"; import './fv_select.js'; @@ -523,7 +524,7 @@ export async function openSetup(options) { // ════════════ Appearance ════════════ const appearance = pane('appearance', t('Appearance', '外观')); const themeSelect = el('select'); - for (const [id, name] of [['dark', t('Dark', '深色')], ['light', t('Light', '浅色')]]) { const o = el('option', '', name); o.value = id; themeSelect.append(o); } + for (const [id, name] of [['dark', t('Dark', '深色')], ['light', translateKey('theme.light')]]) { const o = el('option', '', name); o.value = id; themeSelect.append(o); } themeSelect.value = document.documentElement.dataset.theme === 'light' ? 'light' : 'dark'; themeSelect.onchange = async () => { try { (await import('./shell.js')).setTheme(themeSelect.value); } catch { document.documentElement.dataset.theme = themeSelect.value; } @@ -551,14 +552,14 @@ export async function openSetup(options) { later(onMonitorShown(() => { statusSwitch.checked = statusShown(); })); const statusRow = row({iconName: 'gpu', title: t('Show this computer in the status', '在运行状态中显示本机数据'), sub: t('Graphics memory and temperature in the top bar', '在顶栏显示显存和温度'), end: [statusSwitch]}); const langSelect = el('select'); - for (const [id, name] of [['zh', '中文'], ['en', 'English']]) { const o = el('option', '', name); o.value = id; langSelect.append(o); } - langSelect.value = cn ? 'zh' : 'en'; + for (const [id, name] of [['zh', '中文'], ['en', 'English'], ['pt-BR', translateKey('locale.portuguese')]]) { const o = el('option', '', name); o.value = id; langSelect.append(o); } + langSelect.value = currentLocale(); const langNote = slot(); const langReload = button(t('Reload now', '立即重新载入'), {kind: 'fill', cls: 'is-sm'}); langReload.hidden = true; langNote.textContent = t('Changing the language reloads the page; generations keep running.', '切换语言会重新载入页面,正在进行的生成不受影响。'); - langSelect.onchange = () => { langReload.hidden = langSelect.value === (cn ? 'zh' : 'en'); }; + langSelect.onchange = () => { langReload.hidden = langSelect.value === currentLocale(); }; langReload.onclick = () => { const url = new URL(location.href); url.searchParams.set('freevideo_lang', langSelect.value); location.replace(url.href); }; tip(langReload, t('Reload now', '立即重新载入'), t('Reload the page in the chosen language', '以所选语言重新载入页面')); - const langRow = row({iconName: 'globe', title: t('Interface language', '界面语言'), end: [segmented(langSelect, {label: t('Language', '语言'), tips: {zh: t('Show the interface in Chinese', '界面显示为中文'), en: t('Show the interface in English', '界面显示为英文')}})]}); + const langRow = row({iconName: 'globe', title: t('Interface language', '界面语言'), end: [segmented(langSelect, {label: t('Language', '语言'), tips: {zh: t('Show the interface in Chinese', '界面显示为中文'), en: t('Show the interface in English', '界面显示为英文'), 'pt-BR': translateKey('locale.portuguese')}})]}); const langFoot = el('div', 'st-foot'); langFoot.append(langNote, langReload); appearance.append(groupHead(t('Look', '外观')), card(themeRow.element, solidRow.element), groupHead(t('Top bar', '顶栏')), card(statusRow.element), groupHead(t('Language', '语言')), card(langRow.element, langFoot)); diff --git a/web/settings_words.js b/web/settings_words.js index c22cc79b..ea6cd635 100644 --- a/web/settings_words.js +++ b/web/settings_words.js @@ -1,10 +1,8 @@ +import { currentLocale, translatePair } from './i18n.js'; // Settings' words and rules without the page: the language, sizes, what each installer refusal means and what to do // next, and the pages with the old names callers still pass. No DOM, so tests/settings_words.mjs runs them in Node. -const languageOverride = typeof location !== 'undefined' - ? new URLSearchParams(location.search).get('freevideo_lang') : null; -export const cn = languageOverride === 'zh' || (languageOverride !== 'en' - && String(globalThis.navigator?.language || '').toLowerCase().startsWith('zh')); -export const t = (en, zh) => cn ? zh : en; +export const cn = currentLocale() === 'zh'; +export const t = (en, zh) => translatePair(en, zh, cn); export const INSTALLED_HINT = {en: 'Already installed. To reinstall, click Check installation first.', zh: '已装好。要重装,请先点“检查安装”。'}; export const gib = n => Number.isFinite(n) ? (n / 2 ** 30).toFixed(1) + " GiB" : "—"; // Plan sizes pick their unit, so a few-MB repair does not read as "0.0 GiB". diff --git a/web/studio.js b/web/studio.js index bcef69c4..78941bd3 100644 --- a/web/studio.js +++ b/web/studio.js @@ -1,3 +1,4 @@ +import { currentLocale, translatePair, translateKey } from './i18n.js'; import { cutTip } from './cut_tip.js'; import './has_mirror.js'; import {createLanAccess} from './lan_access.js'; @@ -81,11 +82,8 @@ import { mediaQueue } from './work_media.js'; import { userMessage } from './user_message.js'; import { fieldNote } from './field_note.js'; -const languageOverride = typeof location !== 'undefined' - ? new URLSearchParams(location.search).get('freevideo_lang') : null; -const cn = languageOverride === 'zh' || (languageOverride !== 'en' - && String(navigator.language || '').toLowerCase().startsWith('zh')); -const t = (en, zh) => cn ? zh : en; +const cn = currentLocale() === 'zh'; +const t = (en, zh) => translatePair(en, zh, cn); // A dropped connection gets one plain sentence, not the browser's "Failed to fetch". const shownMessage = error => isNetworkTypeError(error) ? connectionLostText(t) : error.message; // The usual LoRA strength range is -4 to 4; a value the user types by hand may go further, up to 100. @@ -2317,14 +2315,14 @@ export function openStudio(node, {extendFrom = null} = {}) { keyShowsEta = eta; paintEta(); }; // The key has its two lines from the first frame, so its label is in place before anything else is known. - paintKey(t('Generate video', '生成视频'), true); + paintKey(translateKey('ui.generate_video'), true); // Generate's second segment: the menu that says what the key makes, a video or a preview (the same choice as the // two-pass state; a preview turns two-pass on). const keyMore = el('details', null, 'fv-key-more'); const keyMoreToggle = el('summary'); keyMoreToggle.title = t('What to generate', '生成什么'); keyMoreToggle.setAttribute('aria-label', keyMoreToggle.title); keyMoreToggle.append(el('span', null, 'fv-chevron')); const keyMenu = el('div', null, 'fv-run-menu fv-key-menu'); - const keyChoices = [['video', t('Generate video', '生成视频')], ['preview', t('Generate preview', '生成预览')]].map(([id, label]) => { + const keyChoices = [['video', translateKey('ui.generate_video')], ['preview', translateKey('ui.generate_preview')]].map(([id, label]) => { const b = button(label, () => { choosePassMode(id === 'preview' ? 'preview' : twoPass.checked ? 'on' : 'off'); keyMore.open = false; }); b.dataset.choice = id; keyMenu.append(b); return b; }); @@ -2485,7 +2483,7 @@ export function openStudio(node, {extendFrom = null} = {}) { : runMode === 'batch' ? t(`Add ${count.value || '…'} videos`, `添加 ${count.value || '…'} 个视频`) : runMode === 'loop' ? (queueState?.looping ? t('Looping', '循环中') : t('Start loop', '开始循环')) : busy ? t('Add to queue', '加入队列') - : previewFirst.checked && !previewFirst.disabled ? t('Generate preview', '生成预览') : t('Generate video', '生成视频')); + : previewFirst.checked && !previewFirst.disabled ? translateKey('ui.generate_preview') : translateKey('ui.generate_video')); paintKey(borrowed?.label?.() ?? label, borrowed ? true : !submitting && !chainReason); syncKeyMore(); if (borrowed) generate.disabled = borrowed.disabled?.() ?? false; diff --git a/web/task_float.js b/web/task_float.js index 36e8ddea..95121983 100644 --- a/web/task_float.js +++ b/web/task_float.js @@ -1,3 +1,4 @@ +import { currentLocale, translatePair } from './i18n.js'; // The floating window: the generation the user left, in every view and room. It reads the page-wide job store // (task_store.js); it never owns a job. Leaving a view does not stop anything; Stop asks first. // Every view is a modal today, and everything outside the topmost modal is inert, so the window is a @@ -10,9 +11,8 @@ import { errorText, failureAdvice } from './error_panel.js'; import { createImageGenClient, imageGenError, imageReportBar } from './image_generation.js'; import { saveGeneratedImage } from './image_library.js'; -const languageOverride = typeof location !== 'undefined' ? new URLSearchParams(location.search).get('freevideo_lang') : null; -const cn = languageOverride === 'zh' || (languageOverride !== 'en' && String(globalThis.navigator?.language || '').toLowerCase().startsWith('zh')); -const t = (en, zh) => cn ? zh : en; +const cn = currentLocale() === 'zh'; +const t = (en, zh) => translatePair(en, zh, cn); if (typeof document !== 'undefined') { const css = document.createElement('link'); css.rel = 'stylesheet'; css.href = new URL('./task_float.css', import.meta.url).href; document.head.append(css); } diff --git a/web/tooltip.js b/web/tooltip.js index f48dc615..9e09e7e0 100644 --- a/web/tooltip.js +++ b/web/tooltip.js @@ -1,3 +1,4 @@ +import { currentLocale } from './i18n.js'; // One hover tip for every FreeVideo control: a name, one line on what it does and what you get, and its shortcut. // - About 500 ms on a control, then at once on its neighbours while one has just shown; gone ~100 ms after leaving. // - Keyboard focus shows it too; a long press shows it on touch (and that press does not also tap the control). @@ -22,8 +23,7 @@ if (globalThis.document?.head && !globalThis.document.head.querySelector?.('link } const query = new URLSearchParams(globalThis.location?.search || ''); -const language = query.get('freevideo_lang'); -const cn = language === 'zh' || (language !== 'en' && String(globalThis.navigator?.language || '').toLowerCase().startsWith('zh')); +const cn = currentLocale() === 'zh'; const pick = value => Array.isArray(value) ? value[cn ? 1 : 0] : value; export const SHOW_DELAY = 500, HIDE_DELAY = 100, WARM_FOR = 700, GAP = 8, MARGIN = 8, LONG_PRESS = 500, MAX_WIDTH = 320; diff --git a/web/topbar_state.js b/web/topbar_state.js index 9fd53922..c26dd663 100644 --- a/web/topbar_state.js +++ b/web/topbar_state.js @@ -1,10 +1,9 @@ +import { currentLocale, translatePair } from './i18n.js'; // The top bar's words and its status capsule's state, apart from the page (tests/topbar_state.mjs drives them). import { ACTIVE } from './task_store.js'; -const query = new URLSearchParams(globalThis.location?.search || ''); -const language = query.get('freevideo_lang'); -export const CN = language === 'zh' || (language !== 'en' && String(globalThis.navigator?.language || '').toLowerCase().startsWith('zh')); -export const t0 = (en, zh) => CN ? zh : en; +export const CN = currentLocale() === 'zh'; +export const t0 = (en, zh) => translatePair(en, zh, CN); export const MAC = /Mac|iPhone|iPad/i.test(globalThis.navigator?.platform || globalThis.navigator?.userAgent || ''); // The words of the bar, one table (TOPBAR.md §6). Names are what the item is; uses say what it does. diff --git a/web/updates.js b/web/updates.js index f5a4b9f1..da7051d2 100644 --- a/web/updates.js +++ b/web/updates.js @@ -1,3 +1,4 @@ +import { translatePair } from './i18n.js'; import { api } from '../../scripts/api.js'; import { setLauncherPresent, setOfflineInstall } from './repair_hint.js'; import { issueButton } from './issue_button.js'; @@ -51,7 +52,7 @@ const SOUND_ON = '