@@ -7,6 +7,7 @@ import { CookieKeys } from "../../common/http"
7
7
import { rootPath } from "../constants"
8
8
import { authenticated , getCookieOptions , redirect , replaceTemplates } from "../http"
9
9
import { getPasswordMethod , handlePasswordValidation , humanPath , sanitizeString , escapeHtml } from "../util"
10
+ import i18n from "../i18n"
10
11
11
12
// RateLimiter wraps around the limiter library for logins.
12
13
// It allows 2 logins every minute plus 12 logins every hour.
@@ -28,21 +29,26 @@ export class RateLimiter {
28
29
29
30
const getRoot = async ( req : Request , error ?: Error ) : Promise < string > => {
30
31
const content = await fs . readFile ( path . join ( rootPath , "src/browser/pages/login.html" ) , "utf8" )
32
+ const locale = req . args [ "locale" ] || "en"
33
+ i18n . changeLanguage ( locale )
31
34
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 ) } )
34
37
if ( req . args . usingEnvPassword ) {
35
- passwordMsg = "Password was set from $PASSWORD."
38
+ passwordMsg = i18n . t ( "LOGIN_USING_ENV_PASSWORD" )
36
39
} else if ( req . args . usingEnvHashedPassword ) {
37
- passwordMsg = "Password was set from $HASHED_PASSWORD."
40
+ passwordMsg = i18n . t ( "LOGIN_USING_HASHED_PASSWORD" )
38
41
}
39
42
40
43
return replaceTemplates (
41
44
req ,
42
45
content
43
- . replace ( / { { APP _ N A M E } } / g, appName )
46
+ . replace ( / { { I 1 8 N _ L O G I N _ T I T L E } } / g, i18n . t ( "LOGIN_TITLE" , { app : appName } ) )
44
47
. replace ( / { { WELCOME_ T E X T } } / g, welcomeText )
45
48
. replace ( / { { PASSWORD_ M S G } } / g, passwordMsg )
49
+ . replace ( / { { I1 8 N _ L O G I N _ B E L O W } } / g, i18n . t ( "LOGIN_BELOW" ) )
50
+ . 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" ) )
51
+ . replace ( / { { I1 8 N _ S U B M I T } } / g, i18n . t ( "SUBMIT" ) )
46
52
. replace ( / { { ERROR} } / , error ? `<div class="error">${ escapeHtml ( error . message ) } </div>` : "" ) ,
47
53
)
48
54
}
@@ -70,11 +76,11 @@ router.post<{}, string, { password: string; base?: string }, { to?: string }>("/
70
76
try {
71
77
// Check to see if they exceeded their login attempts
72
78
if ( ! limiter . canTry ( ) ) {
73
- throw new Error ( "Login rate limited!" )
79
+ throw new Error ( i18n . t ( "LOGIN_RATE_LIMIT" ) as string )
74
80
}
75
81
76
82
if ( ! password ) {
77
- throw new Error ( "Missing password" )
83
+ throw new Error ( i18n . t ( "MISS_PASSWORD" ) as string )
78
84
}
79
85
80
86
const passwordMethod = getPasswordMethod ( hashedPasswordFromArgs )
@@ -108,7 +114,7 @@ router.post<{}, string, { password: string; base?: string }, { to?: string }>("/
108
114
} ) ,
109
115
)
110
116
111
- throw new Error ( "Incorrect password" )
117
+ throw new Error ( i18n . t ( "INCORRECT_PASSWORD" ) as string )
112
118
} catch ( error : any ) {
113
119
const renderedHtml = await getRoot ( req , error )
114
120
res . send ( renderedHtml )
0 commit comments