Skip to content
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

feat(console): add a declaration file for react-i18next #1556

Merged

Conversation

xiaoyijun
Copy link
Contributor

@xiaoyijun xiaoyijun commented Jul 15, 2022

Summary

According to the react-i18next typescript guide, we need to add a declaration file when we implement our locales template.

  • add a declaration file for react-i18next
  • move files under the languages folder into the locales folder and remove redundant files (en.ts & zh-cn.ts)

Now, the packages/phrases project is well organized:
image

Testing

Tested in IDE and the admin console.

@linear
Copy link

linear bot commented Jul 15, 2022

LOG-3655 Add A Declaration File For `react-i18next`

重构 Phrases 时发现,如果修改了一下 locales 的文件夹名,或者该文件夹下的目录不遵循 locales/en.ts 的模式,useTranslation 函数就无法推断出相关的 i18n key 的类型

https://silverhand-io.slack.com/archives/C02A8G4HVAM/p1657683137715189

最后发现在 Typescript 中使用 i18n 需要创建 declaration file 来指定类型。

故 issue 从

Research: Why I18n Type infer will failed when the locale file is not under the `locales` folder

变为

Add A Declaration File For react-i18next

@github-actions github-actions bot added feature Cool stuff size/s labels Jul 15, 2022
@github-actions
Copy link

COMPARE TO master

Total Size Diff 📉 -108 Bytes

Diff by File
Name Diff
packages/console/src/i18n/react-i18next.d.ts 📉 -255 Bytes
packages/phrases/src/index.ts 📉 -68 Bytes
packages/phrases/src/languages/en/errors.ts 📉 -5.67 KB
packages/phrases/src/languages/en/index.ts 📉 -149 Bytes
packages/phrases/src/languages/en/translation/admin-console/api-resource-details.ts 📉 -600 Bytes
packages/phrases/src/languages/en/translation/admin-console/api-resources.ts 📉 -632 Bytes
packages/phrases/src/languages/en/translation/admin-console/application-details.ts 📉 -2.02 KB
packages/phrases/src/languages/en/translation/admin-console/applications.ts 📉 -1.7 KB
packages/phrases/src/languages/en/translation/admin-console/connector-details.ts 📉 -958 Bytes
packages/phrases/src/languages/en/translation/admin-console/connectors.ts 📉 -1.12 KB
packages/phrases/src/languages/en/translation/admin-console/contact.ts 📉 -581 Bytes
packages/phrases/src/languages/en/translation/admin-console/dashboard.ts 📉 -906 Bytes
packages/phrases/src/languages/en/translation/admin-console/errors.ts 📉 -874 Bytes
packages/phrases/src/languages/en/translation/admin-console/general.ts 📉 -1014 Bytes
packages/phrases/src/languages/en/translation/admin-console/get-started.ts 📉 -1.31 KB
packages/phrases/src/languages/en/translation/admin-console/index.ts 📉 -1.29 KB
packages/phrases/src/languages/en/translation/admin-console/log-details.ts 📉 -386 Bytes
packages/phrases/src/languages/en/translation/admin-console/logs.ts 📉 -252 Bytes
packages/phrases/src/languages/en/translation/admin-console/session-expired.ts 📉 -258 Bytes
packages/phrases/src/languages/en/translation/admin-console/settings.ts 📉 -998 Bytes
packages/phrases/src/languages/en/translation/admin-console/sign-in-exp.ts 📉 -4.02 KB
packages/phrases/src/languages/en/translation/admin-console/tab-sections.ts 📉 -204 Bytes
packages/phrases/src/languages/en/translation/admin-console/tabs.ts 📉 -358 Bytes
packages/phrases/src/languages/en/translation/admin-console/user-details.ts 📉 -1.55 KB
packages/phrases/src/languages/en/translation/admin-console/users.ts 📉 -464 Bytes
packages/phrases/src/languages/en/translation/admin-console/welcome.ts 📉 -328 Bytes
packages/phrases/src/languages/en/translation/demo-app.ts 📉 -522 Bytes
packages/phrases/src/languages/en/translation/index.ts 📉 -164 Bytes
packages/phrases/src/languages/zh-cn/errors.ts 📉 -5.08 KB
packages/phrases/src/languages/zh-cn/index.ts 📉 -188 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/api-resource-details.ts 📉 -539 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/api-resources.ts 📉 -594 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/application-details.ts 📉 -1.91 KB
packages/phrases/src/languages/zh-cn/translation/admin-console/applications.ts 📉 -1.58 KB
packages/phrases/src/languages/zh-cn/translation/admin-console/connector-details.ts 📉 -1014 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/connectors.ts 📉 -1.09 KB
packages/phrases/src/languages/zh-cn/translation/admin-console/contact.ts 📉 -637 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/dashboard.ts 📉 -796 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/errors.ts 📉 -822 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/general.ts 📉 -1004 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/get-started.ts 📉 -1.23 KB
packages/phrases/src/languages/zh-cn/translation/admin-console/index.ts 📉 -1.31 KB
packages/phrases/src/languages/zh-cn/translation/admin-console/log-details.ts 📉 -392 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/logs.ts 📉 -211 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/session-expired.ts 📉 -234 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/settings.ts 📉 -916 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/sign-in-exp.ts 📉 -3.73 KB
packages/phrases/src/languages/zh-cn/translation/admin-console/tab-sections.ts 📉 -191 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/tabs.ts 📉 -350 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/user-details.ts 📉 -1.39 KB
packages/phrases/src/languages/zh-cn/translation/admin-console/users.ts 📉 -453 Bytes
packages/phrases/src/languages/zh-cn/translation/admin-console/welcome.ts 📉 -329 Bytes
packages/phrases/src/languages/zh-cn/translation/demo-app.ts 📉 -514 Bytes
packages/phrases/src/languages/zh-cn/translation/index.ts 📉 -164 Bytes
packages/phrases/src/locales/en.ts 📉 -214 Bytes
packages/phrases/src/locales/en/errors.ts 📉 -5.67 KB
packages/phrases/src/locales/en/index.ts 📉 -149 Bytes
packages/phrases/src/locales/en/translation/admin-console/api-resource-details.ts 📉 -600 Bytes
packages/phrases/src/locales/en/translation/admin-console/api-resources.ts 📉 -632 Bytes
packages/phrases/src/locales/en/translation/admin-console/application-details.ts 📉 -2.02 KB
packages/phrases/src/locales/en/translation/admin-console/applications.ts 📉 -1.7 KB
packages/phrases/src/locales/en/translation/admin-console/connector-details.ts 📉 -958 Bytes
packages/phrases/src/locales/en/translation/admin-console/connectors.ts 📉 -1.12 KB
packages/phrases/src/locales/en/translation/admin-console/contact.ts 📉 -581 Bytes
packages/phrases/src/locales/en/translation/admin-console/dashboard.ts 📉 -906 Bytes
packages/phrases/src/locales/en/translation/admin-console/errors.ts 📉 -874 Bytes
packages/phrases/src/locales/en/translation/admin-console/general.ts 📉 -1014 Bytes
packages/phrases/src/locales/en/translation/admin-console/get-started.ts 📉 -1.31 KB
packages/phrases/src/locales/en/translation/admin-console/index.ts 📉 -1.29 KB
packages/phrases/src/locales/en/translation/admin-console/log-details.ts 📉 -386 Bytes
packages/phrases/src/locales/en/translation/admin-console/logs.ts 📉 -252 Bytes
packages/phrases/src/locales/en/translation/admin-console/session-expired.ts 📉 -258 Bytes
packages/phrases/src/locales/en/translation/admin-console/settings.ts 📉 -998 Bytes
packages/phrases/src/locales/en/translation/admin-console/sign-in-exp.ts 📉 -4.02 KB
packages/phrases/src/locales/en/translation/admin-console/tab-sections.ts 📉 -204 Bytes
packages/phrases/src/locales/en/translation/admin-console/tabs.ts 📉 -358 Bytes
packages/phrases/src/locales/en/translation/admin-console/user-details.ts 📉 -1.55 KB
packages/phrases/src/locales/en/translation/admin-console/users.ts 📉 -464 Bytes
packages/phrases/src/locales/en/translation/admin-console/welcome.ts 📉 -328 Bytes
packages/phrases/src/locales/en/translation/demo-app.ts 📉 -522 Bytes
packages/phrases/src/locales/en/translation/index.ts 📉 -164 Bytes
packages/phrases/src/locales/zh-cn.ts 📉 -217 Bytes
packages/phrases/src/locales/zh-cn/errors.ts 📉 -5.08 KB
packages/phrases/src/locales/zh-cn/index.ts 📉 -188 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/api-resource-details.ts 📉 -539 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/api-resources.ts 📉 -594 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/application-details.ts 📉 -1.91 KB
packages/phrases/src/locales/zh-cn/translation/admin-console/applications.ts 📉 -1.58 KB
packages/phrases/src/locales/zh-cn/translation/admin-console/connector-details.ts 📉 -1014 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/connectors.ts 📉 -1.09 KB
packages/phrases/src/locales/zh-cn/translation/admin-console/contact.ts 📉 -637 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/dashboard.ts 📉 -796 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/errors.ts 📉 -822 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/general.ts 📉 -1004 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/get-started.ts 📉 -1.23 KB
packages/phrases/src/locales/zh-cn/translation/admin-console/index.ts 📉 -1.31 KB
packages/phrases/src/locales/zh-cn/translation/admin-console/log-details.ts 📉 -392 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/logs.ts 📉 -211 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/session-expired.ts 📉 -234 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/settings.ts 📉 -916 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/sign-in-exp.ts 📉 -3.73 KB
packages/phrases/src/locales/zh-cn/translation/admin-console/tab-sections.ts 📉 -191 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/tabs.ts 📉 -350 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/user-details.ts 📉 -1.39 KB
packages/phrases/src/locales/zh-cn/translation/admin-console/users.ts 📉 -453 Bytes
packages/phrases/src/locales/zh-cn/translation/admin-console/welcome.ts 📉 -329 Bytes
packages/phrases/src/locales/zh-cn/translation/demo-app.ts 📉 -514 Bytes
packages/phrases/src/locales/zh-cn/translation/index.ts 📉 -164 Bytes

@xiaoyijun xiaoyijun merged commit 6ae5e7d into master Jul 15, 2022
@xiaoyijun xiaoyijun deleted the xiaoyijun-log-3655-add-a-declaration-file-for-react-i18next branch July 15, 2022 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

2 participants