-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
add i18n support #6006
base: master
Are you sure you want to change the base?
add i18n support #6006
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import i18n from "i18next"; | ||
import LanguageDetector from "i18next-browser-languagedetector"; | ||
import { initReactI18next } from "react-i18next"; | ||
import en from "./locales/en.json"; | ||
import zh from "./locales/zh.json"; | ||
|
||
i18n | ||
.use(initReactI18next) | ||
.use(LanguageDetector) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this automatically enables the translation based on the browser? I think it may be better to leave it disabled until we have more strings translated (or under some feature flag / global settings) |
||
.init({ | ||
resources: { | ||
en: { translation: en }, | ||
zh: { translation: zh }, | ||
}, | ||
fallbackLng: "zh", | ||
preload: ["en", "zh"], | ||
interpolation: { | ||
escapeValue: false, | ||
}, | ||
}); | ||
|
||
export default i18n; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"dashboard": "dashboard" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"dashboard": "看板", | ||
"Favorite Dashboards": "收藏的看板" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,8 @@ | |
"font-awesome": "^4.7.0", | ||
"history": "^4.10.1", | ||
"hoist-non-react-statics": "^3.3.0", | ||
"i18next": "^22.4.15", | ||
"i18next-browser-languagedetector": "^7.0.1", | ||
Comment on lines
+61
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From CI failure it seems it's missing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I pushed yarn.lock file. |
||
"markdown": "0.5.0", | ||
"material-design-iconic-font": "^2.2.0", | ||
"moment": "^2.19.3", | ||
|
@@ -71,6 +73,7 @@ | |
"react-ace": "^9.1.1", | ||
"react-dom": "^16.14.0", | ||
"react-grid-layout": "^0.18.2", | ||
"react-i18next": "^12.2.2", | ||
"react-resizable": "^1.10.1", | ||
"react-virtualized": "^9.21.2", | ||
"sql-formatter": "git+https://github.com/getredash/sql-formatter.git", | ||
|
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.
Out of curiosity, with this
zh
I've often seen it split into two. One for "Simplified Chinese", and one for "Traditional Chinese".Should we have this named as one of them, to leave room for the other one at some future 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.
OK. You are right.
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.
One note is that importing languages like this will add all of them into the bundle, which may not be nice 😅.
It's possibly better to do an async import for those cases. https://www.i18next.com/how-to/add-or-load-translations had a bit of content on this.
Separate thing I was thinking about these days: Should we plan ahead how we will do the translations end-to-end, before committing anything? I don't know much about
react-i18next
, I've used mostly react-intl, the main difference I saw so far is that the later also has adescription
for each unformatted string. Considering Redash as an open-source / community effort and how LLMs are today, it may be a good thing to plan a flow which includes automatic generation of the translation files on every release. Then would count on the community only for reviewing/fixing eventual mistakes, in this case thedescription
would be useful for providing context and/or fixing the prompt.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.
Cool. It's a good idea.
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 haven't figured out which platform to host these mapping tables for the time being.
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.
As a data point - for a project many years ago - we had the project hosted on Launchpad, so it could make use of the translation infrastructure there.
One really cool benefit of that platform at the time was that if anyone, anywhere had translated the same string for any project on Launchpad (with compatible license) then the string was made available as a potential option.
It saved a lot of time for people, and made it easy to get pretty far with new language translations.
That being said, the company behind Launchpad (Canonical) have done some shady stuff in the past so I'm not really a fan of theirs... 😉
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.
The possible use of LLM's for generating "first attempt" translations sounds like a useful idea too.
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.
Cool!