@@ -7,6 +7,7 @@ import { CookieKeys } from "../../common/http"
77import { rootPath } from "../constants"
88import { authenticated , getCookieOptions , redirect , replaceTemplates } from "../http"
99import { getPasswordMethod , handlePasswordValidation , humanPath , sanitizeString , escapeHtml } from "../util"
10+ import i18n from "../i18n"
1011
1112// RateLimiter wraps around the limiter library for logins.
1213// It allows 2 logins every minute plus 12 logins every hour.
@@ -28,13 +29,15 @@ export class RateLimiter {
2829
2930const getRoot = async ( req : Request , error ?: Error ) : Promise < string > => {
3031 const content = await fs . readFile ( path . join ( rootPath , "src/browser/pages/login.html" ) , "utf8" )
32+ const lng = req . args [ "lng" ] || "en"
33+ i18n . changeLanguage ( lng )
3134 const appName = req . args [ "app-name" ] || "code-server"
32- const welcomeText = req . args [ "welcome-text" ] || `Welcome to ${ appName } `
33- let passwordMsg = `Check the config file at ${ humanPath ( os . homedir ( ) , req . args . config ) } for the password.`
35+ const welcomeText = req . args [ "welcome-text" ] || ( i18n . t ( "WELCOME" , { app : appName } ) as string )
36+ let passwordMsg = i18n . t ( "LOGIN_PASSWORD" , { configFile : humanPath ( os . homedir ( ) , req . args . config ) } )
3437 if ( req . args . usingEnvPassword ) {
35- passwordMsg = "Password was set from $PASSWORD."
38+ passwordMsg = i18n . t ( "LOGIN_USING_ENV_PASSWORD" )
3639 } else if ( req . args . usingEnvHashedPassword ) {
37- passwordMsg = "Password was set from $HASHED_PASSWORD."
40+ passwordMsg = i18n . t ( "LOGIN_USING_HASHED_PASSWORD" )
3841 }
3942
4043 return replaceTemplates (
@@ -43,6 +46,10 @@ const getRoot = async (req: Request, error?: Error): Promise<string> => {
4346 . replace ( / { { APP_ N A M E } } / g, appName )
4447 . replace ( / { { WELCOME_ T E X T } } / g, welcomeText )
4548 . replace ( / { { PASSWORD_ M S G } } / g, passwordMsg )
49+ . replace ( / { { I1 8 N _ L O G I N _ T I T L E } } / g, i18n . t ( "LOGIN_TITLE" ) )
50+ . replace ( / { { I1 8 N _ L O G I N _ B E L O W } } / g, i18n . t ( "LOGIN_BELOW" ) )
51+ . replace ( / { { I1 8 N _ P A S S W O R D _ P L A C E H O L D E R } } / g, i18n . t ( "PASSWORD_PLACEHOLDER" ) )
52+ . replace ( / { { I1 8 N _ S U B M I T } } / g, i18n . t ( "SUBMIT" ) )
4653 . replace ( / { { ERROR} } / , error ? `<div class="error">${ escapeHtml ( error . message ) } </div>` : "" ) ,
4754 )
4855}
@@ -70,11 +77,11 @@ router.post<{}, string, { password: string; base?: string }, { to?: string }>("/
7077 try {
7178 // Check to see if they exceeded their login attempts
7279 if ( ! limiter . canTry ( ) ) {
73- throw new Error ( "Login rate limited!" )
80+ throw new Error ( i18n . t ( "LOGIN_RATE_LIMIT" ) as string )
7481 }
7582
7683 if ( ! password ) {
77- throw new Error ( "Missing password" )
84+ throw new Error ( i18n . t ( "MISS_PASSWORD" ) as string )
7885 }
7986
8087 const passwordMethod = getPasswordMethod ( hashedPasswordFromArgs )
@@ -108,7 +115,7 @@ router.post<{}, string, { password: string; base?: string }, { to?: string }>("/
108115 } ) ,
109116 )
110117
111- throw new Error ( "Incorrect password" )
118+ throw new Error ( i18n . t ( "INCORRECT_PASSWORD" ) as string )
112119 } catch ( error : any ) {
113120 const renderedHtml = await getRoot ( req , error )
114121 res . send ( renderedHtml )
0 commit comments