A guided explanation is only useful in a language the reader reads, so the panel header gets a language picker alongside the model one, defaulting to the interface language. Like the model, it is request state rather than a setting: the language travels with the read and the generation, and the one a walkthrough was written in is stored with it, so reopening a review describes what is there instead of what a fresh one would be. Only prose is translated. Hunk aliases resolve back to hunk ids and icon/importance are validated against fixed English values, so a translated one would be dropped by the normalizer — silently losing an anchor or a style. Identifiers and paths stay as they appear in the code. The language is part of the cache key, and a read now asks the cache for the exact request it was given before falling back to the pointer. Without that the panel answered a request to switch languages with the text it already had, leaving the other language unused in the cache. Alongside it: - The answer budget is derived from the resolved model instead of a flat 24k. That number was the same for a 64k-context model and for one that admits to 384k output tokens, and on the latter it was the only reason generation failed: the model spent the whole allowance reasoning and returned nothing. It is now min(96k, max(24k, a quarter of the context)) capped by the catalog's output limit, decided once so the input reserve and the request cannot drift apart. - A read no longer offers Cancel. It is a few hundred milliseconds of git with nothing to cancel, and the button flickered on every model or language change. When the panel is showing a fallback, a banner names what is on screen versus what was asked for — only once the read has settled. - The header keeps one 32px control height and drops its labels below 680px instead of squeezing them to two letters and an ellipsis. Docs and module documentation updated in every locale.
60 lines
2.3 KiB
JavaScript
60 lines
2.3 KiB
JavaScript
// Language the walkthrough prose is written in.
|
|
//
|
|
// This is the server's own list rather than an import from the UI package: the
|
|
// server cannot reach `packages/ui`, and the two lists answer different
|
|
// questions anyway. The UI list is "which locales do we have a dictionary
|
|
// for"; this one is "which languages may we ask a model to write in", and it
|
|
// needs the English endonym-free name that goes into the prompt.
|
|
//
|
|
// The tags match the UI's `Locale` union so the picker can pass its own value
|
|
// straight through. A tag we do not know resolves to English, which is exactly
|
|
// what the feature did before the setting existed.
|
|
|
|
export const DEFAULT_LANGUAGE = 'en';
|
|
|
|
// Value is what the prompt says to write in. Naming the language in English
|
|
// keeps the instruction in the same language as the rest of the system prompt,
|
|
// which every model handles more reliably than a switch mid-sentence.
|
|
const LANGUAGE_NAMES = {
|
|
en: 'English',
|
|
fr: 'French',
|
|
'zh-CN': 'Simplified Chinese',
|
|
'zh-TW': 'Traditional Chinese',
|
|
uk: 'Ukrainian',
|
|
es: 'Spanish',
|
|
'pt-BR': 'Brazilian Portuguese',
|
|
ko: 'Korean',
|
|
pl: 'Polish',
|
|
ja: 'Japanese',
|
|
};
|
|
|
|
/**
|
|
* Coerce a caller-supplied tag to one we support.
|
|
*
|
|
* Unknown, absent, and malformed all collapse to English rather than failing
|
|
* the request: the language is a preference about prose, and refusing to
|
|
* generate a walkthrough over one is a worse answer than writing it in English.
|
|
*/
|
|
export function normalizeLanguage(value) {
|
|
if (typeof value !== 'string' || !value) return DEFAULT_LANGUAGE;
|
|
if (Object.hasOwn(LANGUAGE_NAMES, value)) return value;
|
|
|
|
// Tolerate case and separator drift (`uk-UA`, `pt_br`) so a runtime that
|
|
// passes a platform locale does not silently fall back to English.
|
|
const normalized = value.toLowerCase().replace(/_/g, '-');
|
|
const match = Object.keys(LANGUAGE_NAMES).find((tag) => {
|
|
const lower = tag.toLowerCase();
|
|
return lower === normalized || normalized.startsWith(`${lower}-`);
|
|
});
|
|
if (match) return match;
|
|
|
|
const base = normalized.split('-')[0];
|
|
const baseMatch = Object.keys(LANGUAGE_NAMES).find((tag) => tag.toLowerCase() === base);
|
|
return baseMatch ?? DEFAULT_LANGUAGE;
|
|
}
|
|
|
|
/** English name of a normalized tag, for the prompt. */
|
|
export function languageName(language) {
|
|
return LANGUAGE_NAMES[language] ?? LANGUAGE_NAMES[DEFAULT_LANGUAGE];
|
|
}
|