Skip to content

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

Merged
merged 8 commits into from
Jan 13, 2023
Merged

Conversation

zhaozhiming
Copy link
Contributor

Fixes #5919

@zhaozhiming zhaozhiming requested a review from a team as a code owner January 5, 2023 01:36
Copy link
Contributor

@jsjoeio jsjoeio left a 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

@@ -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 () => {
Copy link
Contributor

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>
Copy link
Contributor

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.

@@ -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>
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member

@code-asher code-asher Jan 6, 2023

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.

Copy link
Contributor Author

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
Comment on lines 271 to 272
Language show on login page, more infomations to read up on
https://en.wikipedia.org/wiki/IETF_language_tag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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 @@
{
Copy link
Member

@code-asher code-asher Jan 5, 2023

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?

Copy link
Contributor Author

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
Copy link

codecov bot commented Jan 5, 2023

Codecov Report

Merging #5947 (9f50607) into main (8377bd2) will increase coverage by 0.13%.
The diff coverage is 86.66%.

Additional details and impacted files

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/node/cli.ts 91.76% <ø> (ø)
src/node/routes/login.ts 87.93% <80.00%> (+0.65%) ⬆️
src/node/i18n/index.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d40a974...9f50607. Read the comment docs.

Copy link
Contributor

@jsjoeio jsjoeio left a 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.

@@ -3,3 +3,5 @@
ci/helm-chart/ @Matthew-Beckett @alexgorbatchev

docs/install.md @GNUxeava

src/node/i18n/locales/zh-cn.json @zhaozhiming
Copy link
Contributor

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

Copy link
Contributor Author

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?

Copy link
Contributor

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!

Copy link
Contributor

@jsjoeio jsjoeio left a 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!

@zhaozhiming
Copy link
Contributor Author

@code-asher Is there anything else I need to do in this PR?

Copy link
Member

@code-asher code-asher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

@jsjoeio jsjoeio enabled auto-merge (squash) January 13, 2023 17:23
@jsjoeio jsjoeio merged commit 7c2aa8c into coder:main Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feat]: Add i18n to the login page
3 participants