-
Notifications
You must be signed in to change notification settings - Fork 5.9k
feat: add i18n in login page #5947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
5f11fac
to
70b9780
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work so far! Mostly a couple minor things and questions.
@@ -22,7 +22,8 @@ | |||
"./test/node_modules/@types", | |||
"./lib/vscode/src/vs/server/@types" | |||
], | |||
"downlevelIteration": true | |||
"downlevelIteration": true, | |||
"resolveJsonModule": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is for importing the locale JSON files in typescript.
test/unit/node/routes/login.test.ts
Outdated
@@ -138,5 +138,16 @@ describe("login", () => { | |||
expect(resp.status).toBe(200) | |||
expect(htmlContent).toContain(`Welcome to ${appName}`) | |||
}) | |||
|
|||
it("should return correct welcome text when lng is set to non-English", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding a test 👏🏼
@@ -25,7 +25,7 @@ | |||
<div class="card-box"> | |||
<div class="header"> | |||
<h1 class="main">{{WELCOME_TEXT}}</h1> | |||
<div class="sub">Please log in below. {{PASSWORD_MSG}}</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of me thinks we should keep the " " here between {{I18N_LOGIN_BELOW}}{{PASSWORD_MSG}}
since I could see someone forgetting to add it to the locales
file.
src/browser/pages/login.html
Outdated
@@ -10,7 +10,7 @@ | |||
http-equiv="Content-Security-Policy" | |||
content="style-src 'self'; script-src 'self' 'unsafe-inline'; manifest-src 'self'; img-src 'self' data:; font-src 'self' data:;" | |||
/> | |||
<title>{{APP_NAME}} login</title> | |||
<title>{{APP_NAME}} {{I18N_LOGIN_TITLE}}</title> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: keeping space...we do it here, so I think we should keep this pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also should the app name be part of the login title? Not sure if in some languages the app name might come after the word for login
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I will put the app name into the whole title.
src/node/cli.ts
Outdated
@@ -88,6 +88,7 @@ export interface UserProvidedArgs extends UserProvidedCodeArgs { | |||
verbose?: boolean | |||
"app-name"?: string | |||
"welcome-text"?: string | |||
"lng"?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd vote for lang
over lng
. I think that's more common? Thoughts?
cc @code-asher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would actually prefer we use the existing --locale
flag since that is what Code uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m a little worried about whether it affects other places when using the existing --locale
flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm...the only place I know is the display language but there may be others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup --locale
is only used to set Code's display language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for example if someone wanted to change the language of code-server and Code all on the command line they would have to do something like:
code-server --lng zh-cn --locale zh-cn
So it seems unfortunate to have to write the same thing twice and it would not be clear to the user why there are two separate flags. In the future this means we can also support changing code-server's display language from the UI which would be cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. That's right. I will change to use the --locale
flag.
src/node/cli.ts
Outdated
Language show on login page, more infomations to read up on | ||
https://en.wikipedia.org/wiki/IETF_language_tag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Language show on login page, more infomations to read up on | |
https://en.wikipedia.org/wiki/IETF_language_tag. | |
Language to show on the login page, more info see | |
https://en.wikipedia.org/wiki/IETF_language_tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had put the description to the --locale
flag.
const appName = req.args["app-name"] || "code-server" | ||
const welcomeText = req.args["welcome-text"] || `Welcome to ${appName}` | ||
let passwordMsg = `Check the config file at ${humanPath(os.homedir(), req.args.config)} for the password.` | ||
const welcomeText = req.args["welcome-text"] || (i18n.t("WELCOME", { app: appName }) as string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this as string
necessary? I would think t
returns a string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the thing I'm struggling with.
Because the t
returns string
or null
( t return type DefaultTFuncReturn).
Although I added returnNull
to the i18n configuration, this config item makes the t
never return null
.
But the TS compiler doesn't seem to know about this, so I need to add as string
.
I'd also like to know if there is a better way to avoid adding as string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can always look in a followup PR. I don't want to hold you back so it's fine as is for now. Thank you for trying that!
@@ -0,0 +1,13 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you be willing to add yourself as a code owner for this file in .github/CODEOWNERS
in case we add new strings in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's my pleasure.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #5947 +/- ##
==========================================
+ Coverage 71.62% 71.75% +0.13%
==========================================
Files 30 31 +1
Lines 1688 1696 +8
Branches 371 372 +1
==========================================
+ Hits 1209 1217 +8
Misses 401 401
Partials 78 78
Continue to review full report at Codecov.
|
70b9780
to
b53a57a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking really good! I think last thing is using lang
instead of lng
.
.github/CODEOWNERS
Outdated
@@ -3,3 +3,5 @@ | |||
ci/helm-chart/ @Matthew-Beckett @alexgorbatchev | |||
|
|||
docs/install.md @GNUxeava | |||
|
|||
src/node/i18n/locales/zh-cn.json @zhaozhiming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: may have to give write access...
Related: https://github.com/orgs/community/discussions/23042
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about .github/CODEOWNERS
. Is there anything else I need to do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, you're good here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Thanks again for doing this!
@code-asher Is there anything else I need to do in this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!!
Fixes #5919