feat: pluggable i18n with English/Chinese language switcher in Settings
Introduces a locale bundle system that makes UI language switchable at runtime and trivially extensible to any future language. Architecture: - static/i18n.js: LOCALES object with 'en' and 'zh' bundles, t(key) helper with English fallback, setLocale()/loadLocale() for persistence via localStorage. Adding a new language = adding one object. - api/config.py: 'language' setting (default 'en'), BCP-47 validation - api/routes.py: _LOGIN_LOCALE dict for server-rendered login page; template placeholders substituted at request time from saved setting - static/index.html: loads i18n.js first (before other scripts); adds Language dropdown to Settings panel, auto-populated from LOCALES Wiring: - boot.js: applies server-persisted locale at startup (after /api/settings fetch); speech recognition lang follows _locale._speech - panels.js: populates Language dropdown from LOCALES on settings open; saves + applies locale on Save Settings - All JS files: hardcoded user-facing strings replaced with t() calls Coverage: - test_sprint20.py: relaxed recognition.lang assertion to accept dynamic locale-driven assignment (behavior unchanged for English default) - 499/499 tests pass Closes #177 (incorporates Chinese translations as a proper locale bundle rather than hardcoded strings, so English default is fully preserved)
This commit is contained in:
@@ -4,8 +4,8 @@ async function cancelStream(){
|
||||
try{
|
||||
await fetch(new URL(`/api/chat/cancel?stream_id=${encodeURIComponent(streamId)}`,location.origin).href,{credentials:'include'});
|
||||
const btn=$('btnCancel');if(btn)btn.style.display='none';
|
||||
setStatus('Cancelling…');
|
||||
}catch(e){setStatus('Cancel failed: '+e.message);}
|
||||
setStatus(t('cancelling'));
|
||||
}catch(e){setStatus(t('cancel_failed')+e.message);}
|
||||
}
|
||||
|
||||
// ── Mobile navigation ──────────────────────────────────────────────────────
|
||||
@@ -66,7 +66,7 @@ $('btnAttach').onclick=()=>$('fileInput').click();
|
||||
const recognition=new SpeechRecognition();
|
||||
recognition.continuous=false;
|
||||
recognition.interimResults=true;
|
||||
recognition.lang='en-US';
|
||||
recognition.lang=(typeof _locale!=='undefined'&&_locale._speech)||'en-US';
|
||||
|
||||
let _finalText='';
|
||||
let _prefix='';
|
||||
@@ -108,11 +108,11 @@ $('btnAttach').onclick=()=>$('fileInput').click();
|
||||
recognition.onerror=(event)=>{
|
||||
_setRecording(false);
|
||||
const msgs={
|
||||
'not-allowed':'Microphone access denied. Check browser permissions.',
|
||||
'no-speech':'No speech detected. Try again.',
|
||||
'network':'Speech recognition unavailable.',
|
||||
'not-allowed':t('mic_denied'),
|
||||
'no-speech':t('mic_no_speech'),
|
||||
'network':t('mic_network'),
|
||||
};
|
||||
showToast(msgs[event.error]||'Voice input error: '+event.error);
|
||||
showToast(msgs[event.error]||t('mic_error')+event.error);
|
||||
};
|
||||
|
||||
function _stopMic(){
|
||||
@@ -160,10 +160,10 @@ $('importFileInput').onchange=async(e)=>{
|
||||
if(res.ok&&res.session){
|
||||
await loadSession(res.session.session_id);
|
||||
await renderSessionList();
|
||||
showToast('Session imported');
|
||||
showToast(t('session_imported'));
|
||||
}
|
||||
}catch(err){
|
||||
showToast('Import failed: '+(err.message||'Invalid JSON'));
|
||||
showToast(t('import_failed')+(err.message||t('import_invalid_json')));
|
||||
}
|
||||
};
|
||||
// btnRefreshFiles is now panel-icon-btn in header (see HTML)
|
||||
@@ -251,7 +251,7 @@ $('msg').addEventListener('paste',e=>{
|
||||
return new File([blob],`screenshot-${Date.now()}.${ext}`,{type:i.type});
|
||||
});
|
||||
addFiles(files);
|
||||
setStatus(`Image pasted: ${files.map(f=>f.name).join(', ')}`);
|
||||
setStatus(t('image_pasted')+files.map(f=>f.name).join(', '));
|
||||
});
|
||||
document.querySelectorAll('.suggestion').forEach(btn=>{
|
||||
btn.onclick=()=>{$('msg').value=btn.dataset.msg;send();};
|
||||
@@ -322,7 +322,7 @@ function applyBotName(){
|
||||
(async()=>{
|
||||
// Load send key preference
|
||||
let _bootSettings={};
|
||||
try{const s=await api('/api/settings');_bootSettings=s;window._sendKey=s.send_key||'enter';window._showTokenUsage=!!s.show_token_usage;window._showCliSessions=!!s.show_cli_sessions;window._soundEnabled=!!s.sound_enabled;window._notificationsEnabled=!!s.notifications_enabled;window._botName=s.bot_name||'Hermes';const _theme=s.theme||'dark';document.documentElement.dataset.theme=_theme;localStorage.setItem('hermes-theme',_theme);applyBotName();}catch(e){window._sendKey='enter';window._showTokenUsage=false;window._showCliSessions=false;window._soundEnabled=false;window._notificationsEnabled=false;window._botName='Hermes';_bootSettings={check_for_updates:false};}
|
||||
try{const s=await api('/api/settings');_bootSettings=s;window._sendKey=s.send_key||'enter';window._showTokenUsage=!!s.show_token_usage;window._showCliSessions=!!s.show_cli_sessions;window._soundEnabled=!!s.sound_enabled;window._notificationsEnabled=!!s.notifications_enabled;window._botName=s.bot_name||'Hermes';const _theme=s.theme||'dark';document.documentElement.dataset.theme=_theme;localStorage.setItem('hermes-theme',_theme);if(s.language&&typeof setLocale==='function'){setLocale(s.language);if(typeof applyLocaleToDOM==='function')applyLocaleToDOM();}applyBotName();}catch(e){window._sendKey='enter';window._showTokenUsage=false;window._showCliSessions=false;window._soundEnabled=false;window._notificationsEnabled=false;window._botName='Hermes';_bootSettings={check_for_updates:false};}
|
||||
// Non-blocking update check (fire-and-forget, once per tab session)
|
||||
// ?test_updates=1 in URL forces banner display for testing (bypasses sessionStorage guards)
|
||||
const _testUpdates=new URLSearchParams(location.search).get('test_updates')==='1';
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
// (no round-trip to the agent) and shows feedback via toast or local message.
|
||||
|
||||
const COMMANDS=[
|
||||
{name:'help', desc:'List available commands', fn:cmdHelp},
|
||||
{name:'clear', desc:'Clear conversation messages', fn:cmdClear},
|
||||
{name:'compact', desc:'Compress conversation context', fn:cmdCompact},
|
||||
{name:'model', desc:'Switch model (e.g. /model gpt-4o)', fn:cmdModel, arg:'model_name'},
|
||||
{name:'workspace', desc:'Switch workspace by name', fn:cmdWorkspace, arg:'name'},
|
||||
{name:'new', desc:'Start a new chat session', fn:cmdNew},
|
||||
{name:'usage', desc:'Toggle token usage display on/off', fn:cmdUsage},
|
||||
{name:'theme', desc:'Switch theme (dark/light/slate/solarized/monokai/nord/oled)', fn:cmdTheme, arg:'name'},
|
||||
{name:'personality', desc:'Switch agent personality', fn:cmdPersonality, arg:'name'},
|
||||
{name:'help', desc:t('cmd_help'), fn:cmdHelp},
|
||||
{name:'clear', desc:t('cmd_clear'), fn:cmdClear},
|
||||
{name:'compact', desc:t('cmd_compact'), fn:cmdCompact},
|
||||
{name:'model', desc:t('cmd_model'), fn:cmdModel, arg:'model_name'},
|
||||
{name:'workspace', desc:t('cmd_workspace'), fn:cmdWorkspace, arg:'name'},
|
||||
{name:'new', desc:t('cmd_new'), fn:cmdNew},
|
||||
{name:'usage', desc:t('cmd_usage'), fn:cmdUsage},
|
||||
{name:'theme', desc:t('cmd_theme'), fn:cmdTheme, arg:'name'},
|
||||
{name:'personality', desc:t('cmd_personality'), fn:cmdPersonality, arg:'name'},
|
||||
];
|
||||
|
||||
function parseCommand(text){
|
||||
@@ -43,10 +43,10 @@ function cmdHelp(){
|
||||
const usage=c.arg?` <${c.arg}>`:'';
|
||||
return ` /${c.name}${usage} — ${c.desc}`;
|
||||
});
|
||||
const msg={role:'assistant',content:'**Available commands:**\n'+lines.join('\n')};
|
||||
const msg={role:'assistant',content:t('available_commands')+'\n'+lines.join('\n')};
|
||||
S.messages.push(msg);
|
||||
renderMessages();
|
||||
showToast('Type / to see commands');
|
||||
showToast(t('type_slash'));
|
||||
}
|
||||
|
||||
function cmdClear(){
|
||||
@@ -55,11 +55,11 @@ function cmdClear(){
|
||||
clearLiveToolCards();
|
||||
renderMessages();
|
||||
$('emptyState').style.display='';
|
||||
showToast('Conversation cleared');
|
||||
showToast(t('conversation_cleared'));
|
||||
}
|
||||
|
||||
async function cmdModel(args){
|
||||
if(!args){showToast('Usage: /model <name>');return;}
|
||||
if(!args){showToast(t('model_usage'));return;}
|
||||
const sel=$('modelSelect');
|
||||
if(!sel)return;
|
||||
const q=args.toLowerCase();
|
||||
@@ -70,36 +70,36 @@ async function cmdModel(args){
|
||||
match=opt.value;break;
|
||||
}
|
||||
}
|
||||
if(!match){showToast(`No model matching "${args}"`);return;}
|
||||
if(!match){showToast(t('no_model_match')+`"${args}"`);return;}
|
||||
sel.value=match;
|
||||
await sel.onchange();
|
||||
showToast(`Switched to ${match}`);
|
||||
showToast(t('switched_to')+match);
|
||||
}
|
||||
|
||||
async function cmdWorkspace(args){
|
||||
if(!args){showToast('Usage: /workspace <name>');return;}
|
||||
if(!args){showToast(t('workspace_usage'));return;}
|
||||
try{
|
||||
const data=await api('/api/workspaces');
|
||||
const q=args.toLowerCase();
|
||||
const ws=(data.workspaces||[]).find(w=>
|
||||
(w.name||'').toLowerCase().includes(q)||w.path.toLowerCase().includes(q)
|
||||
);
|
||||
if(!ws){showToast(`No workspace matching "${args}"`);return;}
|
||||
if(!ws){showToast(t('no_workspace_match')+`"${args}"`);return;}
|
||||
if(!S.session)return;
|
||||
await api('/api/session/update',{method:'POST',body:JSON.stringify({
|
||||
session_id:S.session.session_id,workspace:ws.path,model:S.session.model
|
||||
})});
|
||||
S.session.workspace=ws.path;
|
||||
syncTopbar();await loadDir('.');
|
||||
showToast(`Switched to workspace: ${ws.name||ws.path}`);
|
||||
}catch(e){showToast('Workspace switch failed: '+e.message);}
|
||||
showToast(t('switched_workspace')+(ws.name||ws.path));
|
||||
}catch(e){showToast(t('workspace_switch_failed')+e.message);}
|
||||
}
|
||||
|
||||
async function cmdNew(){
|
||||
await newSession();
|
||||
await renderSessionList();
|
||||
$('msg').focus();
|
||||
showToast('New session created');
|
||||
showToast(t('new_session'));
|
||||
}
|
||||
|
||||
function cmdCompact(){
|
||||
@@ -108,7 +108,7 @@ function cmdCompact(){
|
||||
// We send a user message so it appears in the conversation.
|
||||
$('msg').value='Please compress and summarize the conversation context to free up space.';
|
||||
send();
|
||||
showToast('Requesting context compression...');
|
||||
showToast(t('compressing'));
|
||||
}
|
||||
|
||||
async function cmdUsage(){
|
||||
@@ -121,53 +121,53 @@ async function cmdUsage(){
|
||||
const cb=$('settingsShowTokenUsage');
|
||||
if(cb) cb.checked=next;
|
||||
renderMessages();
|
||||
showToast('Token usage '+(next?'on':'off'));
|
||||
showToast(next?t('token_usage_on'):t('token_usage_off'));
|
||||
}
|
||||
|
||||
async function cmdTheme(args){
|
||||
const themes=['dark','light','slate','solarized','monokai','nord','oled'];
|
||||
if(!args||!themes.includes(args.toLowerCase())){
|
||||
showToast('Usage: /theme '+themes.join('|'));
|
||||
showToast(t('theme_usage')+themes.join('|'));
|
||||
return;
|
||||
}
|
||||
const t=args.toLowerCase();
|
||||
document.documentElement.dataset.theme=t;
|
||||
localStorage.setItem('hermes-theme',t);
|
||||
try{await api('/api/settings',{method:'POST',body:JSON.stringify({theme:t})});}catch(e){}
|
||||
const themeName=args.toLowerCase();
|
||||
document.documentElement.dataset.theme=themeName;
|
||||
localStorage.setItem('hermes-theme',themeName);
|
||||
try{await api('/api/settings',{method:'POST',body:JSON.stringify({theme:themeName})});}catch(e){}
|
||||
// Update settings dropdown if panel is open
|
||||
const sel=$('settingsTheme');
|
||||
if(sel)sel.value=t;
|
||||
showToast('Theme: '+t);
|
||||
if(sel)sel.value=themeName;
|
||||
showToast(t('theme_set')+themeName);
|
||||
}
|
||||
|
||||
async function cmdPersonality(args){
|
||||
if(!S.session){showToast('No active session');return;}
|
||||
if(!S.session){showToast(t('no_active_session'));return;}
|
||||
if(!args){
|
||||
// List available personalities
|
||||
try{
|
||||
const data=await api('/api/personalities');
|
||||
if(!data.personalities||!data.personalities.length){
|
||||
showToast('No personalities found (add them to ~/.hermes/personalities/)');
|
||||
showToast(t('no_personalities'));
|
||||
return;
|
||||
}
|
||||
const list=data.personalities.map(p=>` **${p.name}**${p.description?' — '+p.description:''}`).join('\n');
|
||||
S.messages.push({role:'assistant',content:'Available personalities:\n\n'+list+'\n\nUse `/personality <name>` to switch, or `/personality none` to clear.'});
|
||||
S.messages.push({role:'assistant',content:t('available_personalities')+'\n\n'+list+t('personality_switch_hint')});
|
||||
renderMessages();
|
||||
}catch(e){showToast('Failed to load personalities');}
|
||||
}catch(e){showToast(t('personalities_load_failed'));}
|
||||
return;
|
||||
}
|
||||
const name=args.trim();
|
||||
if(name.toLowerCase()==='none'||name.toLowerCase()==='default'||name.toLowerCase()==='clear'){
|
||||
try{
|
||||
await api('/api/personality/set',{method:'POST',body:JSON.stringify({session_id:S.session.session_id,name:''})});
|
||||
showToast('Personality cleared');
|
||||
}catch(e){showToast('Failed: '+e.message);}
|
||||
showToast(t('personality_cleared'));
|
||||
}catch(e){showToast(t('failed_colon')+e.message);}
|
||||
return;
|
||||
}
|
||||
try{
|
||||
const res=await api('/api/personality/set',{method:'POST',body:JSON.stringify({session_id:S.session.session_id,name})});
|
||||
showToast('Personality: '+name);
|
||||
}catch(e){showToast('Failed: '+e.message);}
|
||||
showToast(t('personality_set')+name);
|
||||
}catch(e){showToast(t('failed_colon')+e.message);}
|
||||
}
|
||||
|
||||
// ── Autocomplete dropdown ───────────────────────────────────────────────────
|
||||
|
||||
289
static/i18n.js
Normal file
289
static/i18n.js
Normal file
@@ -0,0 +1,289 @@
|
||||
// ── i18n: locale bundles and t() helper ──────────────────────────────────────
|
||||
// To add a new language: add an entry to LOCALES below with all keys translated.
|
||||
// The language code must match a valid BCP 47 tag (used for speech recognition).
|
||||
// Keys missing in a non-English locale fall back to English automatically.
|
||||
|
||||
const LOCALES = {
|
||||
en: {
|
||||
_lang: 'en',
|
||||
_label: 'English',
|
||||
_speech: 'en-US',
|
||||
// boot.js
|
||||
cancelling: 'Cancelling\u2026',
|
||||
cancel_failed: 'Cancel failed: ',
|
||||
mic_denied: 'Microphone access denied. Check browser permissions.',
|
||||
mic_no_speech: 'No speech detected. Try again.',
|
||||
mic_network: 'Speech recognition unavailable.',
|
||||
mic_error: 'Voice input error: ',
|
||||
session_imported: 'Session imported',
|
||||
import_failed: 'Import failed: ',
|
||||
import_invalid_json: 'Invalid JSON',
|
||||
image_pasted: 'Image pasted: ',
|
||||
// messages.js
|
||||
edit_message: 'Edit message',
|
||||
regenerate: 'Regenerate response',
|
||||
copy: 'Copy',
|
||||
copied: 'Copied!',
|
||||
you: 'You',
|
||||
thinking: 'Thinking',
|
||||
expand_all: 'Expand all',
|
||||
collapse_all: 'Collapse all',
|
||||
edit_failed: 'Edit failed: ',
|
||||
regen_failed: 'Regenerate failed: ',
|
||||
reconnect_active: 'A response is still being generated. Reload when ready?',
|
||||
reconnect_finished: 'A response was in progress when you last left. Messages may have updated.',
|
||||
untitled: 'Untitled',
|
||||
n_messages: (n) => `${n} messages`,
|
||||
model_unavailable: ' (unavailable)',
|
||||
model_unavailable_title: 'This model is no longer in your current provider list',
|
||||
// commands.js
|
||||
cmd_help: 'List available commands',
|
||||
cmd_clear: 'Clear conversation messages',
|
||||
cmd_compact: 'Compress conversation context',
|
||||
cmd_model: 'Switch model (e.g. /model gpt-4o)',
|
||||
cmd_workspace: 'Switch workspace by name',
|
||||
cmd_new: 'Start a new chat session',
|
||||
cmd_usage: 'Toggle token usage display on/off',
|
||||
cmd_theme: 'Switch theme (dark/light/slate/solarized/monokai/nord/oled)',
|
||||
cmd_personality: 'Switch agent personality',
|
||||
available_commands: 'Available commands:',
|
||||
type_slash: 'Type / to see commands',
|
||||
conversation_cleared: 'Conversation cleared',
|
||||
model_usage: 'Usage: /model <name>',
|
||||
no_model_match: 'No model matching "',
|
||||
switched_to: 'Switched to ',
|
||||
workspace_usage: 'Usage: /workspace <name>',
|
||||
no_workspace_match: 'No workspace matching "',
|
||||
switched_workspace: 'Switched to workspace: ',
|
||||
workspace_switch_failed: 'Workspace switch failed: ',
|
||||
new_session: 'New session created',
|
||||
compressing: 'Requesting context compression...',
|
||||
token_usage_on: 'Token usage on',
|
||||
token_usage_off: 'Token usage off',
|
||||
theme_usage: 'Usage: /theme ',
|
||||
theme_set: 'Theme: ',
|
||||
no_active_session: 'No active session',
|
||||
no_personalities: 'No personalities found (add them to ~/.hermes/personalities/)',
|
||||
available_personalities: 'Available personalities:',
|
||||
personality_switch_hint: '\n\nUse `/personality <name>` to switch, or `/personality none` to clear.',
|
||||
personalities_load_failed: 'Failed to load personalities',
|
||||
personality_cleared: 'Personality cleared',
|
||||
personality_set: 'Personality: ',
|
||||
failed_colon: 'Failed: ',
|
||||
// ui.js
|
||||
no_workspace: 'No workspace',
|
||||
// workspace.js
|
||||
unsaved_confirm: 'You have unsaved changes in the preview. Discard and navigate?',
|
||||
save: 'Save',
|
||||
edit: 'Edit',
|
||||
save_title: 'Save changes',
|
||||
edit_title: 'Edit this file',
|
||||
saved: 'Saved',
|
||||
save_failed: 'Save failed: ',
|
||||
image_load_failed: 'Could not load image',
|
||||
file_open_failed: 'Could not open file',
|
||||
downloading: (name) => `Downloading ${name}\u2026`,
|
||||
double_click_rename: 'Double-click to rename',
|
||||
renamed_to: 'Renamed to ',
|
||||
rename_failed: 'Rename failed: ',
|
||||
delete_title: 'Delete',
|
||||
delete_confirm: (name) => `Delete ${name}?`,
|
||||
deleted: 'Deleted ',
|
||||
delete_failed: 'Delete failed: ',
|
||||
new_file_prompt: 'New file name (e.g. notes.md):',
|
||||
created: 'Created ',
|
||||
create_failed: 'Create failed: ',
|
||||
new_folder_prompt: 'New folder name:',
|
||||
folder_created: 'Created folder ',
|
||||
folder_create_failed: 'Create folder failed: ',
|
||||
remove_title: 'Remove',
|
||||
empty_dir: '(empty)',
|
||||
upload_failed: 'Upload failed: ',
|
||||
all_uploads_failed: (n) => `All ${n} upload(s) failed`,
|
||||
// settings panel
|
||||
settings_title: 'Settings',
|
||||
settings_save_btn: 'Save Settings',
|
||||
settings_label_model: 'Default Model',
|
||||
settings_label_send_key: 'Send Key',
|
||||
settings_label_theme: 'Theme',
|
||||
settings_label_language: 'Language',
|
||||
settings_label_token_usage: 'Show token usage',
|
||||
settings_label_cli_sessions: 'Show CLI sessions',
|
||||
settings_label_sync_insights: 'Sync to insights',
|
||||
settings_label_check_updates: 'Check for updates',
|
||||
settings_label_bot_name: 'Assistant Name',
|
||||
settings_label_password: 'Access Password',
|
||||
settings_saved: 'Settings saved',
|
||||
settings_save_failed: 'Save failed: ',
|
||||
settings_load_failed: 'Failed to load settings: ',
|
||||
settings_saved_pw: 'Settings saved (password set \u2014 login now required)',
|
||||
// login page (used server-side via /api/i18n/login endpoint)
|
||||
login_title: 'Sign in',
|
||||
login_subtitle: 'Enter your password to continue',
|
||||
login_placeholder: 'Password',
|
||||
login_btn: 'Sign in',
|
||||
login_invalid_pw: 'Invalid password',
|
||||
login_conn_failed: 'Connection failed',
|
||||
},
|
||||
|
||||
zh: {
|
||||
_lang: 'zh',
|
||||
_label: '\u4e2d\u6587',
|
||||
_speech: 'zh-CN',
|
||||
// boot.js
|
||||
cancelling: '\u6b63\u5728\u53d6\u6d88...',
|
||||
cancel_failed: '\u53d6\u6d88\u5931\u8d25\uff1a',
|
||||
mic_denied: '\u9ea6\u514b\u98ce\u8bbf\u95ee\u88ab\u62d2\u7edd\uff0c\u8bf7\u68c0\u67e5\u6d4f\u89c8\u5668\u6743\u9650\u3002',
|
||||
mic_no_speech: '\u6ca1\u6709\u68c0\u6d4b\u5230\u8bed\u97f3\uff0c\u8bf7\u518d\u8bd5\u4e00\u6b21\u3002',
|
||||
mic_network: '\u8bed\u97f3\u8bc6\u522b\u5f53\u524d\u4e0d\u53ef\u7528\u3002',
|
||||
mic_error: '\u8bed\u97f3\u8f93\u5165\u51fa\u9519\uff1a',
|
||||
session_imported: '\u4f1a\u8bdd\u5df2\u5bfc\u5165',
|
||||
import_failed: '\u5bfc\u5165\u5931\u8d25\uff1a',
|
||||
import_invalid_json: 'JSON \u65e0\u6548',
|
||||
image_pasted: '\u5df2\u7c98\u8d34\u56fe\u7247\uff1a',
|
||||
// messages.js
|
||||
edit_message: '\u7f16\u8f91\u6d88\u606f',
|
||||
regenerate: '\u91cd\u65b0\u751f\u6210\u56de\u590d',
|
||||
copy: '\u590d\u5236',
|
||||
copied: '\u5df2\u590d\u5236',
|
||||
you: '\u4f60',
|
||||
thinking: '\u601d\u8003\u8fc7\u7a0b',
|
||||
expand_all: '\u5168\u90e8\u5c55\u5f00',
|
||||
collapse_all: '\u5168\u90e8\u6298\u53e0',
|
||||
edit_failed: '\u7f16\u8f91\u5931\u8d25\uff1a',
|
||||
regen_failed: '\u91cd\u65b0\u751f\u6210\u5931\u8d25\uff1a',
|
||||
reconnect_active: '\u56de\u590d\u4ecd\u5728\u751f\u6210\u4e2d\uff0c\u51c6\u5907\u597d\u540e\u8981\u91cd\u65b0\u52a0\u8f7d\u5417\uff1f',
|
||||
reconnect_finished: '\u4f60\u79bb\u5f00\u65f6\u6709\u56de\u590d\u6b63\u5728\u751f\u6210\uff0c\u6d88\u606f\u5185\u5bb9\u53ef\u80fd\u5df2\u7ecf\u66f4\u65b0\u3002',
|
||||
untitled: '\u672a\u547d\u540d',
|
||||
n_messages: (n) => `${n} \u6761\u6d88\u606f`,
|
||||
model_unavailable: '\uff08\u4e0d\u53ef\u7528\uff09',
|
||||
model_unavailable_title: '\u8fd9\u4e2a\u6a21\u578b\u5df2\u7ecf\u4e0d\u5728\u5f53\u524d provider \u5217\u8868\u4e2d',
|
||||
// commands.js
|
||||
cmd_help: '\u67e5\u770b\u53ef\u7528\u547d\u4ee4',
|
||||
cmd_clear: '\u6e05\u7a7a\u5f53\u524d\u5bf9\u8bdd\u6d88\u606f',
|
||||
cmd_compact: '\u538b\u7f29\u5bf9\u8bdd\u4e0a\u4e0b\u6587',
|
||||
cmd_model: '\u5207\u6362\u6a21\u578b\uff08\u4f8b\u5982 /model gpt-4o\uff09',
|
||||
cmd_workspace: '\u6309\u540d\u79f0\u5207\u6362\u5de5\u4f5c\u533a',
|
||||
cmd_new: '\u65b0\u5efa\u804a\u5929\u4f1a\u8bdd',
|
||||
cmd_usage: '\u5207\u6362 token \u7528\u91cf\u663e\u793a',
|
||||
cmd_theme: '\u5207\u6362\u4e3b\u9898\uff08dark/light/slate/solarized/monokai/nord/oled\uff09',
|
||||
cmd_personality: '\u5207\u6362 Agent \u4eba\u8bbe',
|
||||
available_commands: '\u53ef\u7528\u547d\u4ee4\uff1a',
|
||||
type_slash: '\u8f93\u5165 / \u53ef\u67e5\u770b\u547d\u4ee4',
|
||||
conversation_cleared: '\u5bf9\u8bdd\u5df2\u6e05\u7a7a',
|
||||
model_usage: '\u7528\u6cd5\uff1a/model <name>',
|
||||
no_model_match: '\u6ca1\u6709\u5339\u914d\u201c',
|
||||
switched_to: '\u5df2\u5207\u6362\u5230 ',
|
||||
workspace_usage: '\u7528\u6cd5\uff1a/workspace <name>',
|
||||
no_workspace_match: '\u6ca1\u6709\u5339\u914d\u201c',
|
||||
switched_workspace: '\u5df2\u5207\u6362\u5de5\u4f5c\u533a\uff1a',
|
||||
workspace_switch_failed: '\u5de5\u4f5c\u533a\u5207\u6362\u5931\u8d25\uff1a',
|
||||
new_session: '\u5df2\u65b0\u5efa\u4f1a\u8bdd',
|
||||
compressing: '\u6b63\u5728\u8bf7\u6c42\u538b\u7f29\u4e0a\u4e0b\u6587...',
|
||||
token_usage_on: 'Token \u7528\u91cf\u663e\u793a\u5df2\u5f00\u542f',
|
||||
token_usage_off: 'Token \u7528\u91cf\u663e\u793a\u5df2\u5173\u95ed',
|
||||
theme_usage: '\u7528\u6cd5\uff1a/theme ',
|
||||
theme_set: '\u4e3b\u9898\uff1a',
|
||||
no_active_session: '\u5f53\u524d\u6ca1\u6709\u6d3b\u52a8\u4f1a\u8bdd',
|
||||
no_personalities: '\u6ca1\u6709\u627e\u5230\u4eba\u8bbe\uff08\u53ef\u6dfb\u52a0\u5230 ~/.hermes/personalities/\uff09',
|
||||
available_personalities: '\u53ef\u7528\u4eba\u8bbe\uff1a',
|
||||
personality_switch_hint: '\n\n\u4f7f\u7528 `/personality <name>` \u5207\u6362\uff0c\u6216\u7528 `/personality none` \u6e05\u7a7a\u3002',
|
||||
personalities_load_failed: '\u52a0\u8f7d\u4eba\u8bbe\u5931\u8d25',
|
||||
personality_cleared: '\u4eba\u8bbe\u5df2\u6e05\u7a7a',
|
||||
personality_set: '\u5f53\u524d\u4eba\u8bbe\uff1a',
|
||||
failed_colon: '\u5931\u8d25\uff1a',
|
||||
// ui.js
|
||||
no_workspace: '\u672a\u9009\u62e9\u5de5\u4f5c\u533a',
|
||||
// workspace.js
|
||||
unsaved_confirm: '\u9884\u89c8\u533a\u6709\u672a\u4fdd\u5b58\u4fee\u6539\uff0c\u8981\u653e\u5f03\u66f4\u6539\u5e76\u7ee7\u7eed\u8df3\u8f6c\u5417\uff1f',
|
||||
save: '\u4fdd\u5b58',
|
||||
edit: '\u7f16\u8f91',
|
||||
save_title: '\u4fdd\u5b58\u4fee\u6539',
|
||||
edit_title: '\u7f16\u8f91\u6b64\u6587\u4ef6',
|
||||
saved: '\u5df2\u4fdd\u5b58',
|
||||
save_failed: '\u4fdd\u5b58\u5931\u8d25\uff1a',
|
||||
image_load_failed: '\u56fe\u7247\u52a0\u8f7d\u5931\u8d25',
|
||||
file_open_failed: '\u65e0\u6cd5\u6253\u5f00\u6587\u4ef6',
|
||||
downloading: (name) => `\u6b63\u5728\u4e0b\u8f7d ${name}...`,
|
||||
double_click_rename: '\u53cc\u51fb\u91cd\u547d\u540d',
|
||||
renamed_to: '\u5df2\u91cd\u547d\u540d\u4e3a ',
|
||||
rename_failed: '\u91cd\u547d\u540d\u5931\u8d25\uff1a',
|
||||
delete_title: '\u5220\u9664',
|
||||
delete_confirm: (name) => `\u8981\u5220\u9664 ${name} \u5417\uff1f`,
|
||||
deleted: '\u5df2\u5220\u9664 ',
|
||||
delete_failed: '\u5220\u9664\u5931\u8d25\uff1a',
|
||||
new_file_prompt: '\u65b0\u6587\u4ef6\u540d\uff08\u4f8b\u5982 notes.md\uff09\uff1a',
|
||||
created: '\u5df2\u521b\u5efa ',
|
||||
create_failed: '\u521b\u5efa\u5931\u8d25\uff1a',
|
||||
new_folder_prompt: '\u65b0\u6587\u4ef6\u5939\u540d\u79f0\uff1a',
|
||||
folder_created: '\u5df2\u521b\u5efa\u6587\u4ef6\u5939 ',
|
||||
folder_create_failed: '\u521b\u5efa\u6587\u4ef6\u5939\u5931\u8d25\uff1a',
|
||||
remove_title: '\u79fb\u9664',
|
||||
empty_dir: '(\u7a7a)',
|
||||
upload_failed: '\u4e0a\u4f20\u5931\u8d25\uff1a',
|
||||
all_uploads_failed: (n) => `${n} \u4e2a\u6587\u4ef6\u5168\u90e8\u4e0a\u4f20\u5931\u8d25`,
|
||||
// settings panel
|
||||
settings_title: '\u8bbe\u7f6e',
|
||||
settings_save_btn: '\u4fdd\u5b58\u8bbe\u7f6e',
|
||||
settings_label_model: '\u9ed8\u8ba4\u6a21\u578b',
|
||||
settings_label_send_key: '\u53d1\u9001\u5feb\u6377\u952e',
|
||||
settings_label_theme: '\u4e3b\u9898',
|
||||
settings_label_language: '\u8bed\u8a00',
|
||||
settings_label_token_usage: '\u663e\u793a token \u7528\u91cf',
|
||||
settings_label_cli_sessions: '\u663e\u793a CLI \u4f1a\u8bdd',
|
||||
settings_label_sync_insights: '\u540c\u6b65\u5230 insights',
|
||||
settings_label_check_updates: '\u68c0\u67e5\u66f4\u65b0',
|
||||
settings_label_bot_name: '\u52a9\u624b\u540d\u79f0',
|
||||
settings_label_password: '\u8bbf\u95ee\u5bc6\u7801',
|
||||
settings_saved: '\u8bbe\u7f6e\u5df2\u4fdd\u5b58',
|
||||
settings_save_failed: '\u4fdd\u5b58\u5931\u8d25\uff1a',
|
||||
settings_load_failed: '\u8bbe\u7f6e\u52a0\u8f7d\u5931\u8d25\uff1a',
|
||||
settings_saved_pw: '\u8bbe\u7f6e\u5df2\u4fdd\u5b58\uff08\u5bc6\u7801\u5df2\u8bbe\u7f6e\u2014\u73b0\u5728\u9700\u8981\u767b\u5f55\uff09',
|
||||
// login page
|
||||
login_title: '\u767b\u5f55',
|
||||
login_subtitle: '\u8f93\u5165\u5bc6\u7801\u7ee7\u7eed\u4f7f\u7528',
|
||||
login_placeholder: '\u5bc6\u7801',
|
||||
login_btn: '\u767b\u5f55',
|
||||
login_invalid_pw: '\u5bc6\u7801\u9519\u8bef',
|
||||
login_conn_failed: '\u8fde\u63a5\u5931\u8d25',
|
||||
},
|
||||
};
|
||||
|
||||
// Active locale — defaults to English; overridden by loadLocale() at boot.
|
||||
let _locale = LOCALES.en;
|
||||
|
||||
/**
|
||||
* Translate a key. Falls back to English if the key is missing in the active locale.
|
||||
* Supports function values (for interpolated strings): call t('key', arg).
|
||||
* @param {string} key
|
||||
* @param {...*} args - forwarded to function-valued translations
|
||||
* @returns {string}
|
||||
*/
|
||||
function t(key, ...args) {
|
||||
const val = _locale[key] ?? LOCALES.en[key];
|
||||
if (val === undefined) return key; // final fallback: return key itself
|
||||
return typeof val === 'function' ? val(...args) : val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch locale by language code (e.g. 'en', 'zh').
|
||||
* Persists to localStorage and updates the <html lang> attribute.
|
||||
* @param {string} lang
|
||||
*/
|
||||
function setLocale(lang) {
|
||||
_locale = LOCALES[lang] || LOCALES.en;
|
||||
localStorage.setItem('hermes-lang', lang);
|
||||
document.documentElement.lang = _locale._speech || lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load locale from localStorage (called once at boot, before DOMContentLoaded).
|
||||
* Server-persisted preference is applied later in loadSettingsPanel().
|
||||
*/
|
||||
function loadLocale() {
|
||||
const saved = localStorage.getItem('hermes-lang') || 'en';
|
||||
setLocale(saved);
|
||||
}
|
||||
|
||||
// Apply saved locale immediately so there's no flash of English on reload.
|
||||
loadLocale();
|
||||
@@ -345,6 +345,10 @@
|
||||
<option value="oled">OLED</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="settings-field">
|
||||
<label for="settingsLanguage">Language</label>
|
||||
<select id="settingsLanguage" style="width:100%;padding:8px;background:var(--code-bg);color:var(--text);border:1px solid var(--border2);border-radius:6px"></select>
|
||||
</div>
|
||||
<div class="settings-field">
|
||||
<label style="display:flex;align-items:center;gap:8px;cursor:pointer">
|
||||
<input type="checkbox" id="settingsSoundEnabled" style="width:15px;height:15px;accent-color:var(--accent)">
|
||||
@@ -427,6 +431,7 @@
|
||||
</button>
|
||||
</nav>
|
||||
<div class="toast" id="toast"></div>
|
||||
<script src="/static/i18n.js"></script>
|
||||
<script src="/static/ui.js"></script>
|
||||
<script src="/static/workspace.js"></script>
|
||||
<script src="/static/sessions.js"></script>
|
||||
|
||||
@@ -975,6 +975,8 @@ function _markSettingsDirty(){
|
||||
async function loadSettingsPanel(){
|
||||
try{
|
||||
const settings=await api('/api/settings');
|
||||
// Apply server-persisted locale immediately (overrides localStorage boot default)
|
||||
if(settings.language && typeof setLocale==='function') setLocale(settings.language);
|
||||
// Populate model dropdown from /api/models
|
||||
const modelSel=$('settingsModel');
|
||||
if(modelSel){
|
||||
@@ -1001,6 +1003,20 @@ async function loadSettingsPanel(){
|
||||
// Theme preference
|
||||
const themeSel=$('settingsTheme');
|
||||
if(themeSel){themeSel.value=settings.theme||'dark';themeSel.addEventListener('change',_markSettingsDirty,{once:false});}
|
||||
// Language preference — populate from LOCALES bundle
|
||||
const langSel=$('settingsLanguage');
|
||||
if(langSel){
|
||||
langSel.innerHTML='';
|
||||
if(typeof LOCALES!=='undefined'){
|
||||
for(const [code,bundle] of Object.entries(LOCALES)){
|
||||
const opt=document.createElement('option');
|
||||
opt.value=code;opt.textContent=bundle._label||code;
|
||||
langSel.appendChild(opt);
|
||||
}
|
||||
}
|
||||
langSel.value=settings.language||'en';
|
||||
langSel.addEventListener('change',_markSettingsDirty,{once:false});
|
||||
}
|
||||
const showUsageCb=$('settingsShowTokenUsage');
|
||||
if(showUsageCb){showUsageCb.checked=!!settings.show_token_usage;showUsageCb.addEventListener('change',_markSettingsDirty,{once:false});}
|
||||
const showCliCb=$('settingsShowCliSessions');
|
||||
@@ -1029,7 +1045,7 @@ async function loadSettingsPanel(){
|
||||
if(disableBtn) disableBtn.style.display=active?'':'none';
|
||||
}catch(e){}
|
||||
}catch(e){
|
||||
showToast('Failed to load settings: '+e.message);
|
||||
showToast(t('settings_load_failed')+e.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1040,11 +1056,13 @@ async function saveSettings(andClose){
|
||||
const showCliSessions=!!($('settingsShowCliSessions')||{}).checked;
|
||||
const pw=($('settingsPassword')||{}).value;
|
||||
const theme=($('settingsTheme')||{}).value||'dark';
|
||||
const language=($('settingsLanguage')||{}).value||'en';
|
||||
const body={};
|
||||
if(model) body.default_model=model;
|
||||
|
||||
if(sendKey) body.send_key=sendKey;
|
||||
body.theme=theme;
|
||||
body.language=language;
|
||||
body.show_token_usage=showTokenUsage;
|
||||
body.show_cli_sessions=showCliSessions;
|
||||
body.sync_to_insights=!!($('settingsSyncInsights')||{}).checked;
|
||||
@@ -1061,7 +1079,9 @@ async function saveSettings(andClose){
|
||||
window._showTokenUsage=showTokenUsage;
|
||||
window._soundEnabled=body.sound_enabled;
|
||||
window._notificationsEnabled=body.notifications_enabled;
|
||||
showToast('Settings saved (password set — login now required)');
|
||||
if(typeof setLocale==='function') setLocale(language);
|
||||
if(typeof applyLocaleToDOM==='function') applyLocaleToDOM();
|
||||
showToast(t('settings_saved_pw'));
|
||||
_settingsDirty=false; _settingsThemeOnOpen=theme;
|
||||
const bar=$('settingsUnsavedBar'); if(bar) bar.style.display='none';
|
||||
$('settingsOverlay').style.display='none';
|
||||
@@ -1077,14 +1097,15 @@ async function saveSettings(andClose){
|
||||
window._notificationsEnabled=body.notifications_enabled;
|
||||
window._botName=body.bot_name;
|
||||
if(typeof applyBotName==='function') applyBotName();
|
||||
if(typeof setLocale==='function') setLocale(language);
|
||||
_settingsDirty=false; _settingsThemeOnOpen=theme;
|
||||
const bar=$('settingsUnsavedBar'); if(bar) bar.style.display='none';
|
||||
renderMessages();
|
||||
if(typeof renderSessionList==='function') renderSessionList();
|
||||
showToast('Settings saved');
|
||||
showToast(t('settings_saved'));
|
||||
$('settingsOverlay').style.display='none';
|
||||
}catch(e){
|
||||
showToast('Save failed: '+e.message);
|
||||
showToast(t('settings_save_failed')+e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
70
static/ui.js
70
static/ui.js
@@ -387,12 +387,12 @@ async function checkInflightOnBoot(sid) {
|
||||
const status = await api(`/api/chat/stream/status?stream_id=${encodeURIComponent(streamId || '')}`);
|
||||
if (status.active) {
|
||||
// Stream is genuinely still running -- show the banner
|
||||
showReconnectBanner('A response is still being generated. Reload when ready?');
|
||||
showReconnectBanner(t('reconnect_active'));
|
||||
} else {
|
||||
// Stream finished. Only show banner if reload happened within 90 seconds
|
||||
// (longer gap = normal completed session, not a mid-stream reload)
|
||||
if (Date.now() - ts < 90 * 1000) {
|
||||
showReconnectBanner('A response was in progress when you last left. Messages may have updated.');
|
||||
showReconnectBanner(t('reconnect_finished'));
|
||||
} else {
|
||||
clearInflight(); // completed normally, no banner needed
|
||||
}
|
||||
@@ -406,15 +406,15 @@ function syncTopbar(){
|
||||
// Show default workspace name even without a session
|
||||
const sidebarName=$('sidebarWsName');
|
||||
if(sidebarName && sidebarName.textContent==='Workspace'){
|
||||
sidebarName.textContent='No workspace';
|
||||
sidebarName.textContent=t('no_workspace');
|
||||
}
|
||||
return;
|
||||
}
|
||||
const sessionTitle=S.session.title||'Untitled';
|
||||
const sessionTitle=S.session.title||t('untitled');
|
||||
$('topbarTitle').textContent=sessionTitle;
|
||||
document.title=sessionTitle+' \u2014 '+(window._botName||'Hermes');
|
||||
const vis=S.messages.filter(m=>m&&m.role&&m.role!=='tool');
|
||||
$('topbarMeta').textContent=`${vis.length} messages`;
|
||||
$('topbarMeta').textContent=t('n_messages',vis.length);
|
||||
// If a profile switch just happened, apply its model rather than the session's stale value.
|
||||
// S._pendingProfileModel is set by switchToProfile() and cleared here after one application.
|
||||
const modelOverride=S._pendingProfileModel;
|
||||
@@ -431,9 +431,9 @@ function syncTopbar(){
|
||||
if(!applied && m){
|
||||
const opt=document.createElement('option');
|
||||
opt.value=m;
|
||||
opt.textContent=getModelLabel(m)+' (unavailable)';
|
||||
opt.textContent=getModelLabel(m)+t('model_unavailable');
|
||||
opt.style.color='var(--muted, #888)';
|
||||
opt.title='This model is no longer in your current provider list';
|
||||
opt.title=t('model_unavailable_title');
|
||||
$('modelSelect').appendChild(opt);
|
||||
$('modelSelect').value=m;
|
||||
}
|
||||
@@ -524,7 +524,7 @@ function renderMessages(){
|
||||
// Render thinking card before the assistant message (collapsed by default)
|
||||
if(thinkingText&&!isUser){
|
||||
const thinkRow=document.createElement('div');thinkRow.className='msg-row thinking-card-row';
|
||||
thinkRow.innerHTML=`<div class="thinking-card"><div class="thinking-card-header" onclick="this.parentElement.classList.toggle('open')"><span class="thinking-card-icon">💡</span><span class="thinking-card-label">Thinking</span><span class="thinking-card-toggle">▸</span></div><div class="thinking-card-body"><pre>${esc(thinkingText)}</pre></div></div>`;
|
||||
thinkRow.innerHTML=`<div class="thinking-card"><div class="thinking-card-header" onclick="this.parentElement.classList.toggle('open')"><span class="thinking-card-icon">💡</span><span class="thinking-card-label">${t('thinking')}</span><span class="thinking-card-toggle">▸</span></div><div class="thinking-card-body"><pre>${esc(thinkingText)}</pre></div></div>`;
|
||||
inner.appendChild(thinkRow);
|
||||
}
|
||||
const row=document.createElement('div');row.className='msg-row';
|
||||
@@ -534,12 +534,12 @@ function renderMessages(){
|
||||
filesHtml=`<div class="msg-files">${m.attachments.map(f=>`<div class="msg-file-badge">📎 ${esc(f)}</div>`).join('')}</div>`;
|
||||
const bodyHtml = isUser ? esc(String(content)).replace(/\n/g,'<br>') : renderMd(String(content));
|
||||
// Action buttons for this bubble
|
||||
const editBtn = isUser ? `<button class="msg-action-btn" title="Edit message" onclick="editMessage(this)">✎</button>` : '';
|
||||
const retryBtn = isLastAssistant ? `<button class="msg-action-btn" title="Regenerate response" onclick="regenerateResponse(this)">↻</button>` : '';
|
||||
const editBtn = isUser ? `<button class="msg-action-btn" title="${t('edit_message')}" onclick="editMessage(this)">✎</button>` : '';
|
||||
const retryBtn = isLastAssistant ? `<button class="msg-action-btn" title="${t('regenerate')}" onclick="regenerateResponse(this)">↻</button>` : '';
|
||||
const tsVal=m._ts||m.timestamp;
|
||||
const tsTitle=tsVal?new Date(tsVal*1000).toLocaleString():'';
|
||||
const _bn=window._botName||'Hermes';
|
||||
row.innerHTML=`<div class="msg-role ${m.role}" ${tsTitle?`title="${esc(tsTitle)}"`:''}><div class="role-icon ${m.role}">${isUser?'Y':esc(_bn.charAt(0).toUpperCase())}</div><span style="font-size:12px">${isUser?'You':esc(_bn)}</span>${tsTitle?`<span class="msg-time">${new Date(tsVal*1000).toLocaleTimeString([],{hour:'2-digit',minute:'2-digit'})}</span>`:''}<span class="msg-actions">${editBtn}<button class="msg-copy-btn msg-action-btn" title="Copy" onclick="copyMsg(this)">📋</button>${retryBtn}</span></div>${filesHtml}<div class="msg-body">${bodyHtml}</div>`;
|
||||
row.innerHTML=`<div class="msg-role ${m.role}" ${tsTitle?`title="${esc(tsTitle)}"`:''}}><div class="role-icon ${m.role}">${isUser?'Y':esc(_bn.charAt(0).toUpperCase())}</div><span style="font-size:12px">${isUser?t('you'):esc(_bn)}</span>${tsTitle?`<span class="msg-time">${new Date(tsVal*1000).toLocaleTimeString([],{hour:'2-digit',minute:'2-digit'})}</span>`:''}<span class="msg-actions">${editBtn}<button class="msg-copy-btn msg-action-btn" title="${t('copy')}" onclick="copyMsg(this)">📋</button>${retryBtn}</span></div>${filesHtml}<div class="msg-body">${bodyHtml}</div>`;
|
||||
row.dataset.rawText = String(content).trim();
|
||||
inner.appendChild(row);
|
||||
}
|
||||
@@ -617,10 +617,10 @@ function renderMessages(){
|
||||
// Collect card elements before they get moved to DOM
|
||||
const cardEls=Array.from(frag.querySelectorAll('.tool-card'));
|
||||
const expandBtn=document.createElement('button');
|
||||
expandBtn.textContent='Expand all';
|
||||
expandBtn.textContent=t('expand_all');
|
||||
expandBtn.onclick=()=>cardEls.forEach(c=>c.classList.add('open'));
|
||||
const collapseBtn=document.createElement('button');
|
||||
collapseBtn.textContent='Collapse all';
|
||||
collapseBtn.textContent=t('collapse_all');
|
||||
collapseBtn.onclick=()=>cardEls.forEach(c=>c.classList.remove('open'));
|
||||
toggle.appendChild(expandBtn);
|
||||
toggle.appendChild(collapseBtn);
|
||||
@@ -807,7 +807,7 @@ async function submitEdit(msgIdx, newText) {
|
||||
// Now send the edited message as a new chat
|
||||
$('msg').value = newText;
|
||||
await send();
|
||||
} catch(e) { setStatus('Edit failed: ' + e.message); }
|
||||
} catch(e) { setStatus(t('edit_failed') + e.message); }
|
||||
}
|
||||
|
||||
async function regenerateResponse(btn) {
|
||||
@@ -833,7 +833,7 @@ async function regenerateResponse(btn) {
|
||||
renderMessages();
|
||||
$('msg').value = lastUserText;
|
||||
await send();
|
||||
} catch(e) { setStatus('Regenerate failed: ' + e.message); }
|
||||
} catch(e) { setStatus(t('regen_failed') + e.message); }
|
||||
}
|
||||
|
||||
function highlightCode(container) {
|
||||
@@ -852,12 +852,12 @@ function addCopyButtons(container){
|
||||
if(pre.querySelector('.code-copy-btn')) return;
|
||||
const btn=document.createElement('button');
|
||||
btn.className='code-copy-btn';
|
||||
btn.textContent='Copy';
|
||||
btn.textContent=t('copy');
|
||||
btn.onclick=(e)=>{
|
||||
e.stopPropagation();
|
||||
navigator.clipboard.writeText(codeEl.textContent).then(()=>{
|
||||
btn.textContent='Copied!';
|
||||
setTimeout(()=>{btn.textContent='Copy';},1500);
|
||||
btn.textContent=t('copied');
|
||||
setTimeout(()=>{btn.textContent=t('copy');},1500);
|
||||
});
|
||||
};
|
||||
const header=pre.previousElementSibling;
|
||||
@@ -1010,7 +1010,7 @@ function _renderTreeItems(container, entries, depth){
|
||||
|
||||
// Name
|
||||
const nameEl=document.createElement('span');
|
||||
nameEl.className='file-name';nameEl.textContent=item.name;nameEl.title='Double-click to rename';
|
||||
nameEl.className='file-name';nameEl.textContent=item.name;nameEl.title=t('double_click_rename');
|
||||
nameEl.ondblclick=(e)=>{
|
||||
e.stopPropagation();
|
||||
// For directories, double-click navigates (breadcrumb view)
|
||||
@@ -1027,11 +1027,11 @@ function _renderTreeItems(container, entries, depth){
|
||||
await api('/api/file/rename',{method:'POST',body:JSON.stringify({
|
||||
session_id:S.session.session_id,path:item.path,new_name:newName
|
||||
})});
|
||||
showToast(`Renamed to ${newName}`);
|
||||
showToast(t('renamed_to')+newName);
|
||||
// Invalidate cache and re-render
|
||||
delete S._dirCache[S.currentDir];
|
||||
await loadDir(S.currentDir);
|
||||
}catch(err){showToast('Rename failed: '+err.message);}
|
||||
}catch(err){showToast(t('rename_failed')+err.message);}
|
||||
}
|
||||
}
|
||||
inp.replaceWith(nameEl);
|
||||
@@ -1057,7 +1057,7 @@ function _renderTreeItems(container, entries, depth){
|
||||
// Delete button -- for files
|
||||
if(item.type==='file'){
|
||||
const del=document.createElement('button');
|
||||
del.className='file-del-btn';del.title='Delete';del.textContent='\u00d7';
|
||||
del.className='file-del-btn';del.title=t('delete_title');del.textContent='\u00d7';
|
||||
del.onclick=async(e)=>{e.stopPropagation();await deleteWorkspaceFile(item.path,item.name);};
|
||||
el.appendChild(del);
|
||||
}
|
||||
@@ -1098,7 +1098,7 @@ function _renderTreeItems(container, entries, depth){
|
||||
const empty=document.createElement('div');
|
||||
empty.className='file-item file-empty';
|
||||
empty.style.paddingLeft=(8+(depth+1)*16)+'px';
|
||||
empty.textContent='(empty)';
|
||||
empty.textContent=t('empty_dir');
|
||||
container.appendChild(empty);
|
||||
}
|
||||
}
|
||||
@@ -1107,39 +1107,39 @@ function _renderTreeItems(container, entries, depth){
|
||||
|
||||
async function deleteWorkspaceFile(relPath, name){
|
||||
if(!S.session)return;
|
||||
if(!confirm(`Delete ${name}?`))return;
|
||||
if(!confirm(t('delete_confirm',name)))return;
|
||||
try{
|
||||
await api('/api/file/delete',{method:'POST',body:JSON.stringify({session_id:S.session.session_id,path:relPath})});
|
||||
showToast(`Deleted ${name}`);
|
||||
showToast(t('deleted')+name);
|
||||
// Close preview if we just deleted the viewed file
|
||||
if($('previewPathText').textContent===relPath)$('btnClearPreview').onclick();
|
||||
await loadDir(S.currentDir);
|
||||
}catch(e){setStatus('Delete failed: '+e.message);}
|
||||
}catch(e){setStatus(t('delete_failed')+e.message);}
|
||||
}
|
||||
|
||||
async function promptNewFile(){
|
||||
if(!S.session)return;
|
||||
const name=prompt('New file name (e.g. notes.md):','');
|
||||
const name=prompt(t('new_file_prompt'),'');
|
||||
if(!name||!name.trim())return;
|
||||
const relPath=S.currentDir==='.'?name.trim():(S.currentDir+'/'+name.trim());
|
||||
try{
|
||||
await api('/api/file/create',{method:'POST',body:JSON.stringify({session_id:S.session.session_id,path:relPath,content:''})});
|
||||
showToast(`Created ${name.trim()}`);
|
||||
showToast(t('created')+name.trim());
|
||||
await loadDir(S.currentDir);
|
||||
openFile(relPath);
|
||||
}catch(e){setStatus('Create failed: '+e.message);}
|
||||
}catch(e){setStatus(t('create_failed')+e.message);}
|
||||
}
|
||||
|
||||
async function promptNewFolder(){
|
||||
if(!S.session)return;
|
||||
const name=prompt('New folder name:','');
|
||||
const name=prompt(t('new_folder_prompt'),'');
|
||||
if(!name||!name.trim())return;
|
||||
const relPath=S.currentDir==='.'?name.trim():(S.currentDir+'/'+name.trim());
|
||||
try{
|
||||
await api('/api/file/create-dir',{method:'POST',body:JSON.stringify({session_id:S.session.session_id,path:relPath})});
|
||||
showToast(`Created folder ${name.trim()}`);
|
||||
showToast(t('folder_created')+name.trim());
|
||||
await loadDir(S.currentDir);
|
||||
}catch(e){setStatus('Create folder failed: '+e.message);}
|
||||
}catch(e){setStatus(t('folder_create_failed')+e.message);}
|
||||
}
|
||||
|
||||
function renderTray(){
|
||||
@@ -1149,7 +1149,7 @@ function renderTray(){
|
||||
updateSendBtn();
|
||||
S.pendingFiles.forEach((f,i)=>{
|
||||
const chip=document.createElement('div');chip.className='attach-chip';
|
||||
chip.innerHTML=`📎 ${esc(f.name)} <button title="Remove">✕</button>`;
|
||||
chip.innerHTML=`📎 ${esc(f.name)} <button title="${t('remove_title')}">✕</button>`;
|
||||
chip.querySelector('button').onclick=()=>{S.pendingFiles.splice(i,1);renderTray();};
|
||||
tray.appendChild(chip);
|
||||
});
|
||||
@@ -1171,12 +1171,12 @@ async function uploadPendingFiles(){
|
||||
const data=await res.json();
|
||||
if(data.error)throw new Error(data.error);
|
||||
names.push(data.filename);
|
||||
}catch(e){failures++;setStatus(`\u274c Upload failed: ${f.name} \u2014 ${e.message}`);}
|
||||
}catch(e){failures++;setStatus(`\u274c ${t('upload_failed')}${f.name} \u2014 ${e.message}`);}
|
||||
bar.style.width=`${Math.round((i+1)/total*100)}%`;
|
||||
}
|
||||
barWrap.classList.remove('active');bar.style.width='0%';
|
||||
S.pendingFiles=[];renderTray();
|
||||
if(failures===total&&total>0)throw new Error(`All ${total} upload(s) failed`);
|
||||
if(failures===total&&total>0)throw new Error(t('all_uploads_failed',total));
|
||||
return names;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ async function loadDir(path){
|
||||
}
|
||||
if(typeof clearPreview==='function'){
|
||||
if(typeof _previewDirty!=='undefined'&&_previewDirty){
|
||||
if(confirm('You have unsaved changes in the preview. Discard and navigate?'))clearPreview();
|
||||
if(confirm(t('unsaved_confirm')))clearPreview();
|
||||
}else{
|
||||
clearPreview();
|
||||
}
|
||||
@@ -131,8 +131,8 @@ function updateEditBtn(){
|
||||
const editable = _previewCurrentMode==='code'||_previewCurrentMode==='md';
|
||||
btn.style.display = editable?'':'none';
|
||||
const editing = $('previewEditArea').style.display!=='none';
|
||||
btn.innerHTML = editing ? '💾 Save' : '✎ Edit';
|
||||
btn.title = editing ? 'Save changes' : 'Edit this file';
|
||||
btn.innerHTML = editing ? `💾 ${t('save')}` : `✎ ${t('edit')}`;
|
||||
btn.title = editing ? t('save_title') : t('edit_title');
|
||||
btn.style.color = editing ? 'var(--blue)' : '';
|
||||
if(_previewDirty) btn.innerHTML = '💾 Save*';
|
||||
}
|
||||
@@ -154,8 +154,8 @@ async function toggleEditMode(){
|
||||
$('previewEditArea').style.display='none';
|
||||
if(_previewCurrentMode==='code') $('previewCode').style.display='';
|
||||
else $('previewMd').style.display='';
|
||||
showToast('Saved');
|
||||
}catch(e){setStatus('Save failed: '+e.message);}
|
||||
showToast(t('saved'));
|
||||
}catch(e){setStatus(t('save_failed')+e.message);}
|
||||
}else{
|
||||
// Enter edit mode: populate textarea with current content
|
||||
const currentText = _previewCurrentMode==='code'
|
||||
@@ -206,7 +206,7 @@ async function openFile(path){
|
||||
const url=`/api/file/raw?session_id=${encodeURIComponent(S.session.session_id)}&path=${encodeURIComponent(path)}`;
|
||||
$('previewImg').alt=path;
|
||||
$('previewImg').src=url;
|
||||
$('previewImg').onerror=()=>setStatus('Could not load image');
|
||||
$('previewImg').onerror=()=>setStatus(t('image_load_failed'));
|
||||
} else if(MD_EXTS.has(ext)){
|
||||
// Markdown: fetch text, render with renderMd, display as formatted HTML
|
||||
try{
|
||||
@@ -214,7 +214,7 @@ async function openFile(path){
|
||||
showPreview('md');
|
||||
_previewRawContent = data.content;
|
||||
$('previewMd').innerHTML=renderMd(data.content);
|
||||
}catch(e){setStatus('Could not open file');}
|
||||
}catch(e){setStatus(t('file_open_failed'));}
|
||||
} else {
|
||||
// Plain code / text -- but fall back to download if server signals binary
|
||||
try{
|
||||
@@ -242,6 +242,6 @@ function downloadFile(path){
|
||||
a.href=url;a.download=filename;
|
||||
document.body.appendChild(a);a.click();
|
||||
setTimeout(()=>document.body.removeChild(a),100);
|
||||
showToast(`Downloading ${filename}\u2026`,2000);
|
||||
showToast(t('downloading',filename),2000);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user