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

🐛 fix: antd i18n miss error #1083

Merged
merged 4 commits into from
Jan 19, 2024

Conversation

Wxh16144
Copy link
Contributor

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • ⚡️ perf
  • 📝 docs

🔀 变更说明 | Description of Change

📝 补充信息 | Additional Information

Copy link

vercel bot commented Jan 17, 2024

@Wxh16144 is attempting to deploy a commit to the LobeHub Team on Vercel.

A member of the Team first needs to authorize it.

@lobehubbot
Copy link
Member

👍 @Wxh16144

Thank you for raising your pull request and contributing to our Community
Please make sure you have followed our contributing guidelines. We will review it as soon as possible.
If you encounter any problems, please feel free to connect with us.
非常感谢您提出拉取请求并为我们的社区做出贡献,请确保您已经遵循了我们的贡献指南,我们会尽快审查它。
如果您遇到任何问题,请随时与我们联系。

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (fix/antd-i18n@7253fd5). Click here to learn what that means.

❗ Current head 95e17a9 differs from pull request most recent head ea24177. Consider uploading reports for the commit ea24177 to get more accurate results

Additional details and impacted files
@@               Coverage Diff                @@
##             fix/antd-i18n    #1083   +/-   ##
================================================
  Coverage                 ?   88.62%           
================================================
  Files                    ?      177           
  Lines                    ?     8350           
  Branches                 ?      953           
================================================
  Hits                     ?     7400           
  Misses                   ?      950           
  Partials                 ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Wxh16144
Copy link
Contributor Author

本地运行项目,看起来 antd locale 文件加载有问题。(点击这里的删除,弹出的确认弹窗可验证
image

async () => {
const localeName = lang?.includes('-') ? lang?.replace('-', '_') : 'en_US';
const antdLocale = await import(`antd/locale/${localeName}.js`);
return antdLocale.default ?? antdLocale;
Copy link
Contributor

Choose a reason for hiding this comment

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

之前 antd i18n 不生效是因为这里没 .default ?

Copy link
Member

Choose a reason for hiding this comment

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

大吃一惊

Copy link

vercel bot commented Jan 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lobe-chat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 18, 2024 9:45am

@arvinxx
Copy link
Contributor

arvinxx commented Jan 17, 2024

@Wxh16144 还是不对呀:

image

@Wxh16144
Copy link
Contributor Author

@Wxh16144 还是不对呀:

我懂了,默认打开时候是英文,设置里面设置为其他语言后,需要重新刷一下,我看看 swr 是不是需要手动再更新一下🤔

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@Wxh16144 Still wrong:

I understand, it opens in English by default. After setting it to other languages ​​in the settings, you need to refresh it. Let me see if swr needs to be updated manually🤔

@arvinxx
Copy link
Contributor

arvinxx commented Jan 18, 2024

@Wxh16144 还是不对呀:

我懂了,默认打开时候是英文,设置里面设置为其他语言后,需要重新刷一下,我看看 swr 是不是需要手动再更新一下🤔

Swr在 key发生变化的时候会自动做重新请求的

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@Wxh16144 Still wrong:

I understand, it opens in English by default. After setting it to other languages ​​in the settings, you need to refresh it. Let me see if swr needs to be updated manually🤔

Swr will automatically re-request when the key changes.

@Wxh16144
Copy link
Contributor Author

有一个已知问题,#1049 添加了新的语言,只提供了国家,没有提供区域,无法正确的得到 antd 支持的语言。 cc @MEClouds

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


There is a known issue, #1049 Added new languages, only country provided, not region, Unable to get language supported by antd correctly. cc @MEClouds

@arvinxx
Copy link
Contributor

arvinxx commented Jan 18, 2024

有一个已知问题,#1049 添加了新的语言,只提供了国家,没有提供区域,无法正确的得到 antd 支持的语言。 cc @MEClouds

可以在这里做处理:

https://github.com/lobehub/lobe-chat/blob/main/src/locales/resources.ts#L22-L42

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


There is a known issue, #1049 Added new languages, [only country provided, not region](https://github.com/lobehub/lobe-chat/pull/1049/files#diff-45dde41c13f9728d7bc1c3a8649fb53c18d74020fcd414f41740c9f02ef46b09R4 7) , unable to correctly obtain language supported by antd. cc @MEClouds

This can be done here:

https://github.com/lobehub/lobe-chat/blob/main/src/locales/resources.ts#L22-L42

@arvinxx
Copy link
Contributor

arvinxx commented Jan 18, 2024

但是为啥 antd 支持的是 ar-EG ?

@lobehubbot
Copy link
Member

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


But why does antd support ar-EG?

@MEClouds
Copy link
Contributor

MEClouds commented Jan 18, 2024

Update normalizeLocale Function:
Modify the normalizeLocale function to handle the 'ar' case and provide a fallback locale ('ar-EG' in this case):

export const normalizeLocale = (locale: string) => {
  switch (locale) {
    case 'zh-CN':
    case 'zh': {
      return 'zh-CN';
    }
    case 'en': {
      return 'en-US';
    }
    case 'ar': {
      return 'ar-EG'; // Fallback to a supported locale for Arabic
    }
    default: {
      return locale;
    }
  }
};

Then can use it with the import statement: :

import(`antd/locale/${normalizeLocale(lang!).replace('-', '_')}.js`),

[FETCH_ANTD_LOCALE, lang],
async ([, l]) => {
const localeName = l?.includes('-') ? l?.replace('-', '_') : 'en_US';
const antdLocale = await import(`antd/locale/${localeName}.js`);
Copy link
Contributor

@MEClouds MEClouds Jan 18, 2024

Choose a reason for hiding this comment

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

i think you can use normalizeLocale function just import it from '@/locales/resources';

const antdLocale = await import(`antd/locale/${normalizeLocale(lang!).replace('-', '_')}.js`);

or

 const localeName =normalizeLocale(l!).replace('-', '_');
 const antdLocale = await import(`antd/locale/${localeName}.js`);

@arvinxx arvinxx changed the base branch from main to fix/antd-i18n January 19, 2024 12:38
Copy link
Contributor

@arvinxx arvinxx left a comment

Choose a reason for hiding this comment

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

@Wxh16144 冲突解决下?我先合到 fix/antd-i18n 里再改改

@arvinxx arvinxx changed the base branch from fix/antd-i18n to fix-antd-i18n January 19, 2024 12:49
@arvinxx arvinxx merged commit 4a38f6e into lobehub:fix-antd-i18n Jan 19, 2024
1 of 2 checks passed
@lobehubbot
Copy link
Member

❤️ Great PR @Wxh16144 ❤️

The growth of project is inseparable from user feedback and contribution, thanks for your contribution! If you are interesting with the lobehub developer community, please join our discord and then dm @arvinxx or @canisminor1990. They will invite you to our private developer channel. We are talking about the lobe-chat development or sharing ai newsletter around the world.
项目的成长离不开用户反馈和贡献,感谢您的贡献! 如果您对 LobeHub 开发者社区感兴趣,请加入我们的 discord,然后私信 @arvinxx@canisminor1990。他们会邀请您加入我们的私密开发者频道。我们将会讨论关于 Lobe Chat 的开发,分享和讨论全球范围内的 AI 消息。

@arvinxx arvinxx mentioned this pull request Jan 19, 2024
7 tasks
arvinxx pushed a commit that referenced this pull request Jan 19, 2024
* 📝 docs(bot): Auto sync agents & plugin to readme

* 🐛 fix: antd i18n miss error

* 🐛 fix: update logic

* 🍻 chore: update

---------

Co-authored-by: lobehubbot <i@lobehub.com>
arvinxx added a commit that referenced this pull request Jan 19, 2024
* 🐛 fix: antd i18n miss error (#1083)

* 📝 docs(bot): Auto sync agents & plugin to readme

* 🐛 fix: antd i18n miss error

* 🐛 fix: update logic

* 🍻 chore: update

---------

Co-authored-by: lobehubbot <i@lobehub.com>

* 🐛 fix: fix antd locale fetch

* 🐛 fix: fix antd locale fetch

* 🐛 fix: fix antd locale fetch

---------

Co-authored-by: 红 <wxh1220@gmail.com>
Co-authored-by: lobehubbot <i@lobehub.com>
github-actions bot pushed a commit that referenced this pull request Jan 19, 2024
### [Version&nbsp;0.120.3](v0.120.2...v0.120.3)
<sup>Released on **2024-01-19**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor antd i18n and improve locale order.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Refactor antd i18n and improve locale order, closes [#1103](#1103) [#1083](#1083) ([c89f527](c89f527))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
@lobehubbot
Copy link
Member

🎉 This PR is included in version 0.120.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

github-actions bot pushed a commit to bentwnghk/lobe-chat that referenced this pull request Jan 19, 2024
### [Version&nbsp;1.2.3](v1.2.2...v1.2.3)
<sup>Released on **2024-01-19**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor antd i18n and improve locale order.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Refactor antd i18n and improve locale order, closes [lobehub#1103](https://github.com/bentwnghk/lobe-chat/issues/1103) [lobehub#1083](https://github.com/bentwnghk/lobe-chat/issues/1083) ([c89f527](c89f527))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
miroshar-success added a commit to miroshar-success/OpenAI_Integraion_platform that referenced this pull request Apr 5, 2024
### [Version&nbsp;0.120.3](lobehub/lobe-chat@v0.120.2...v0.120.3)
<sup>Released on **2024-01-19**</sup>

#### ♻ Code Refactoring

- **misc**: Refactor antd i18n and improve locale order.

<br/>

<details>
<summary><kbd>Improvements and Fixes</kbd></summary>

#### Code refactoring

* **misc**: Refactor antd i18n and improve locale order, closes [#1103](lobehub/lobe-chat#1103) [#1083](lobehub/lobe-chat#1083) ([c89f527](lobehub/lobe-chat@c89f527))

</details>

<div align="right">

[![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)

</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants