feat: add i18n in login page#5947
Conversation
5f11fac to
70b9780
Compare
jsjoeio
left a comment
There was a problem hiding this comment.
Great work so far! Mostly a couple minor things and questions.
| ], | ||
| "downlevelIteration": true | ||
| "downlevelIteration": true, | ||
| "resolveJsonModule": true |
There was a problem hiding this comment.
There was a problem hiding this comment.
Yes, this is for importing the locale JSON files in typescript.
| 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.
Thank you for adding a test 👏🏼
| <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.
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.
| 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.
Re: keeping space...we do it here, so I think we should keep this pattern.
There was a problem hiding this comment.
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.
ok. I will put the app name into the whole title.
| verbose?: boolean | ||
| "app-name"?: string | ||
| "welcome-text"?: string | ||
| "lng"?: string |
There was a problem hiding this comment.
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.
I would actually prefer we use the existing --locale flag since that is what Code uses.
There was a problem hiding this comment.
I’m a little worried about whether it affects other places when using the existing --locale flag?
There was a problem hiding this comment.
Hmm...the only place I know is the display language but there may be others.
There was a problem hiding this comment.
Yup --locale is only used to set Code's display language.
There was a problem hiding this comment.
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.
ok. That's right. I will change to use the --locale flag.
| 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.
| 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.
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.
Is this as string necessary? I would think t returns a string
There was a problem hiding this comment.
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.
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.
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.
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
jsjoeio
left a comment
There was a problem hiding this comment.
Looking really good! I think last thing is using lang instead of lng.
|
|
||
| docs/install.md @GNUxeava | ||
|
|
||
| src/node/i18n/locales/zh-cn.json @zhaozhiming No newline at end of file |
There was a problem hiding this comment.
Note to self: may have to give write access...
Related: https://github.com/orgs/community/discussions/23042
There was a problem hiding this comment.
I don't know much about .github/CODEOWNERS. Is there anything else I need to do?
jsjoeio
left a comment
There was a problem hiding this comment.
Nice work! Thanks again for doing this!
|
@code-asher Is there anything else I need to do in this PR? |
Fixes #5919