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: [plugin-local] 添加 getLocal API 获取当前用户选择的语言 #228

Merged
merged 1 commit into from
Jan 24, 2024

Conversation

winixt
Copy link
Collaborator

@winixt winixt commented Jan 23, 2024

What kind of change does this PR introduce? (check at least one)

  • Feature

Does this PR introduce a breaking change? (check one)

  • No

@@ -82,6 +86,7 @@ const t = (key) => {

const locale = {
setLocale,
getLocale,
addLocale,
getAllLocales,
messages,

Choose a reason for hiding this comment

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

这个代码补丁有以下问题和改进建议:

  1. addLocale 函数中, messages[locale] 被错误地分配成自身。应该使用不同的变量名来避免覆盖。例如,可以将其更改为 messages[locale] = newMessages

  2. t 函数中,需要处理当缺少关键字参数时,返回默认文本或者一个警告信息。

  3. 变量命名方面,getLocale 可以更明确一些,例如改为 getCurrentLocale

  4. 如果可能,建议对所有参数进行输入验证并添加适当的错误处理。

  5. 代码中的注释非常重要。如果没有任何注释,建议添加合适的注释,解释每个函数的用途和参数的含义。

  6. 对于 setLocale 函数,应该考虑检查传入的 locale 参数是否有效。如果传递了无效的值,可能会导致错误或不一致性。

  7. 最后,建议在代码提交之前进行测试,确保所做的更改没有引入新的错误,并且在不同的情况下都能正常工作。

@wanchun wanchun merged commit 5c7bdca into master Jan 24, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants