Add language customization flag (#7374)

This allows you to customize any string (that has a translation) or add your own translations.
This commit is contained in:
Alex Strick van Linschoten
2025-07-15 22:38:27 +02:00
committed by GitHub
parent 8b3d9b9e0a
commit 92fca0dcc3
8 changed files with 471 additions and 23 deletions

View File

@@ -31,23 +31,32 @@ const getRoot = async (req: Request, error?: Error): Promise<string> => {
const locale = req.args["locale"] || "en"
i18n.changeLanguage(locale)
const appName = req.args["app-name"] || "code-server"
const welcomeText = req.args["welcome-text"] || (i18n.t("WELCOME", { app: appName }) as string)
const welcomeText = escapeHtml(req.args["welcome-text"] || (i18n.t("WELCOME", { app: appName }) as string))
// Determine password message using i18n
let passwordMsg = i18n.t("LOGIN_PASSWORD", { configFile: req.args.config })
if (req.args.usingEnvPassword) {
passwordMsg = i18n.t("LOGIN_USING_ENV_PASSWORD")
} else if (req.args.usingEnvHashedPassword) {
passwordMsg = i18n.t("LOGIN_USING_HASHED_PASSWORD")
}
passwordMsg = escapeHtml(passwordMsg)
// Get messages from i18n (with HTML escaping for security)
const loginTitle = escapeHtml(i18n.t("LOGIN_TITLE", { app: appName }))
const loginBelow = escapeHtml(i18n.t("LOGIN_BELOW"))
const passwordPlaceholder = escapeHtml(i18n.t("PASSWORD_PLACEHOLDER"))
const submitText = escapeHtml(i18n.t("SUBMIT"))
return replaceTemplates(
req,
content
.replace(/{{I18N_LOGIN_TITLE}}/g, i18n.t("LOGIN_TITLE", { app: appName }))
.replace(/{{I18N_LOGIN_TITLE}}/g, loginTitle)
.replace(/{{WELCOME_TEXT}}/g, welcomeText)
.replace(/{{PASSWORD_MSG}}/g, passwordMsg)
.replace(/{{I18N_LOGIN_BELOW}}/g, i18n.t("LOGIN_BELOW"))
.replace(/{{I18N_PASSWORD_PLACEHOLDER}}/g, i18n.t("PASSWORD_PLACEHOLDER"))
.replace(/{{I18N_SUBMIT}}/g, i18n.t("SUBMIT"))
.replace(/{{I18N_LOGIN_BELOW}}/g, loginBelow)
.replace(/{{I18N_PASSWORD_PLACEHOLDER}}/g, passwordPlaceholder)
.replace(/{{I18N_SUBMIT}}/g, submitText)
.replace(/{{ERROR}}/, error ? `<div class="error">${escapeHtml(error.message)}</div>` : ""),
)
}