Skip to content

[Feat]: Add i18n to the login page #5919

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

Closed
zhaozhiming opened this issue Dec 23, 2022 · 8 comments · Fixed by #5947
Closed

[Feat]: Add i18n to the login page #5919

zhaozhiming opened this issue Dec 23, 2022 · 8 comments · Fixed by #5947
Labels
enhancement Some improvement that isn't a feature

Comments

@zhaozhiming
Copy link
Contributor

What is your suggestion?

Add i18n to the login page

Why do you want this feature?

I want to display the login page in a different language.

Are there any workarounds to get this functionality today?

No. Use the welcome-text parameter only to translate partial content to what language I want on the login page.

Are you interested in submitting a PR for this?

Yes. Something like this:
image

@zhaozhiming zhaozhiming added the enhancement Some improvement that isn't a feature label Dec 23, 2022
@jsjoeio
Copy link
Contributor

jsjoeio commented Jan 3, 2023

@code-asher what are your thoughts on this?

@code-asher
Copy link
Member

code-asher commented Jan 3, 2023 via email

@code-asher
Copy link
Member

code-asher commented Jan 3, 2023

I am imagining a JSON file like this:

{
  "Welcome to {appName}": "hey there hello this is {appName} have fun"
}

And we use it roughly like so (untested and could probably be optimized):

function i18n(str, args) {
  if (locale !== "en") {
    try {
      const translations = require(locale + ".json")
      if (typeof translations[str] === "undefined") {
        throw new Error(`${locale} has no translations for ${str}`)
      }
      str = translations[str]
    } catch (error) {
      // Maybe log once?
    }
  }
  if (typeof args !== "undefined") {
    for (const key in args) {
      str = str.replace(new RegExp("\\{" + key + "\\}", "g"), args[key]);
    }
  }
  return str
}
// ...
const welcomeText = req.args["welcome-text"] || i18n("Welcome to {appName}", { appName })

@jsjoeio jsjoeio added this to the On Deck - High Priority milestone Jan 3, 2023
@jsjoeio
Copy link
Contributor

jsjoeio commented Jan 3, 2023

That makes sense to me! And seems like it would be straightforward enough to implement.

Only question that comes to mind: would we maintain those translation files?

I wonder if alternatively, we could tell the user to place it in a specific location and then read from there.

Benefits: we don't end up maintaining language translations we don't know and we don't increase size of code-server with a bunch of text files.

Thoughts?

@code-asher
Copy link
Member

code-asher commented Jan 3, 2023 via email

@jsjoeio
Copy link
Contributor

jsjoeio commented Jan 3, 2023

it could
be unfairly punishing to non-English speakers.

Definitely wouldn't want that so good point.

We may want to add code owners when someone submits or edits a
translation file.

Seems easy enough!

In this case those strings fall back to English and
if a user reports those we can ask they go bug the translation
file owner or submit their own translation. :P

Agreed, seems like a solid approach.

Sounds like we have a plan and we think this is worth doing!

@zhaozhiming
Copy link
Contributor Author

I'm happy to see the feature suggestion be accepted.
Most of @code-asher ideas are the same as mine.
I've implemented it on my local machine and am glad to submit a PR.

@jsjoeio
Copy link
Contributor

jsjoeio commented Jan 4, 2023

@zhaozhiming that would be amazing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Some improvement that isn't a feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants