Add lightweight i18n foundation; route new strings through catalogs
- Backend src/i18n.rs: embedded locales/<lang>.json, t(key,params) with {placeholder} interpolation, process-wide language from config.language (default it), English-then-key fallback. Applied to the identity reminder and name-lock/empty errors.
- Frontend: web/assets/locales/<lang>.json + t()/loadI18n()/applyI18n() (data-i18n attributes); language follows the browser; async bootstrap. Applied to the settings panel.
- Convention: new user-facing and model-facing strings use the catalog; wire/JSON/identifiers never translated. Existing strings migrate in a later round. it+en catalogs; 115 tests; verified live (catalog error messages) + node --check + HTTP. README documents the convention.
This commit is contained in:
1 parent
73b665d1a7
commit
498e3dbc1b
12 files changed
+248
-27
No files matched your search
+5
-6
@@ -19,6 +19,7 @@ use super::routes::{AppState, Error};
|
||||
use super::types::{ChatChunk, ChatMessage, ChatRequest, FunctionCall, Role, ToolCall, Usage};
|
||||
use crate::agent::shell::{HostShell, ShellRunner};
|
||||
use crate::agent::{self, AgentEvent};
|
||||
use crate::i18n::t;
|
||||
use crate::name;
|
||||
use crate::store::{NewMessage, Session, SessionSettings, Stats, Store, StoredMessage};
|
||||
use tokio_stream::wrappers::UnboundedReceiverStream;
|
||||
@@ -137,13 +138,11 @@ pub(crate) async fn patch_session(
|
||||
.ok_or_else(|| Error::not_found("session not found"))?;
|
||||
if let Some(title) = body.title {
|
||||
if sess.name_locked {
|
||||
return Err(Error::bad_request(
|
||||
"the session name is immutable after the first interaction",
|
||||
));
|
||||
return Err(Error::bad_request(t("error.name_locked", &[])));
|
||||
}
|
||||
let title = title.trim().to_string();
|
||||
if title.is_empty() {
|
||||
return Err(Error::bad_request("name must not be empty"));
|
||||
return Err(Error::bad_request(t("error.name_empty", &[])));
|
||||
}
|
||||
with_store(&st, {
|
||||
let id = id.clone();
|
||||
@@ -213,9 +212,9 @@ fn build_request(sess: &Session, history: &[StoredMessage], body: &SessionChat)
|
||||
let mut messages = Vec::new();
|
||||
// Structural identity reminder: always present, not an editable setting. It
|
||||
// tells the agent its name and personal workspace folder.
|
||||
let mut identity = format!("Il tuo nome è {}.", sess.title);
|
||||
let mut identity = t("identity.name", &[("name", &sess.title)]);
|
||||
if let Some(folder) = &sess.folder {
|
||||
identity.push_str(&format!(" La tua cartella personale è {folder}."));
|
||||
identity.push_str(&t("identity.folder", &[("folder", folder)]));
|
||||
}
|
||||
messages.push(text_message(Role::System, identity));
|
||||
if let Some(sp) = &sess.settings.system_prompt {
|
||||
|
||||
Reference in new issue
Block a user