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(i18n/gi18n): add key-value translation pattern #3829

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

lxy1151
Copy link

@lxy1151 lxy1151 commented Sep 29, 2024

多语言翻译:修复翻译语句参数顺序发生变化时,参数值的顺序还是原来的bug。

林孝义 and others added 13 commits July 31, 2024 16:48
修改多语言替换和参数无关
修改多语言替换和参数无关
修改多语言替换和参数无关
修改多语言替换和参数无关
修改多语言替换和参数无关
还原无关文件
修改多语言替换和参数无关
还原无关文件
处理测试不通过问题
return result
}
}
return fmt.Sprintf(result, values...)
Copy link
Member

@gqcn gqcn Oct 8, 2024

Choose a reason for hiding this comment

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

实现键值对替换的特性是很不错的,但是这里实现有两点小问题:

  • 直接在TranslateFormat方法中修改违背了这个方法的设计含义,建议提供新方法比如TranslateMap/Tm来实现准确的语义更合适一些。
  • 至于键值对替换中对于键的格式如何定义,感觉直接使用:key的格式有点太宽泛了,使用模板引擎的方式是不是更合适一些(但是又和模板引擎似乎冲突了),这块看大家有什么建议?

Copy link
Author

Choose a reason for hiding this comment

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

TranslateFormat 这个方法如果不做处理,翻译后参数位置变了,就不准确了,比如第一个位置的参数,翻译后位置变到第三个了,如果还是按原来的翻译参数顺序就不对了。个人觉得还是要兼容修复下比较好。

Copy link
Member

Choose a reason for hiding this comment

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

@lxy1151 TranslateFormat的设计就是format中的站位符号和values的顺序是对应的,所以我才说新建一个方法来做不同的事情,设计的逻辑清晰一些。

Copy link
Author

Choose a reason for hiding this comment

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

新增TranslateMap方法?

Copy link
Member

Choose a reason for hiding this comment

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

新增TranslateMap方法?

我个人建议是这样的,至少在原有方法上改不太合适,大家也可以一起来讨论下。

Copy link
Author

Choose a reason for hiding this comment

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

已经修改。
增加了TranslateMap方法
增加了Tm快捷方法

@gqcn gqcn added the discuss We need discuss to make decision. label Oct 8, 2024
@gqcn gqcn changed the title Fixed muliti lang transfer feat(i18n/gi18n): add key-value translation pattern Oct 8, 2024
修改多语言替换和参数无关
还原无关文件
处理测试不通过问题
增加了Tm快捷方法
增加了TranslateMap方法
@lxy1151 lxy1151 requested a review from gqcn October 23, 2024 03:02
if len(mpStrStr) > 0 {
for k, v := range mpStrStr {
rpKey := ":" + k
result = strings.ReplaceAll(result, rpKey, v)
Copy link
Member

Choose a reason for hiding this comment

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

  • 我不确定:key这种模式是否最优雅的替换方式,可以参考其他i18n的转译是使用的什么格式来做的替换。
  • 这里直接使用ReplaceAll似乎也不是很优雅,例如有两个变量:key1:key2,在替换的时候使用key则会把它们都替换掉了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss We need discuss to make decision.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants