-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: master
Are you sure you want to change the base?
Conversation
修改多语言替换和参数无关
修改多语言替换和参数无关
修改多语言替换和参数无关
修改多语言替换和参数无关
修改多语言替换和参数无关 还原无关文件
修改多语言替换和参数无关 还原无关文件 处理测试不通过问题
撤销session的变更,只处理多语言
i18n/gi18n/gi18n_manager.go
Outdated
return result | ||
} | ||
} | ||
return fmt.Sprintf(result, values...) |
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.
实现键值对替换的特性是很不错的,但是这里实现有两点小问题:
- 直接在
TranslateFormat
方法中修改违背了这个方法的设计含义,建议提供新方法比如TranslateMap/Tm
来实现准确的语义更合适一些。 - 至于键值对替换中对于键的格式如何定义,感觉直接使用
:key
的格式有点太宽泛了,使用模板引擎的方式是不是更合适一些(但是又和模板引擎似乎冲突了),这块看大家有什么建议?
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.
TranslateFormat 这个方法如果不做处理,翻译后参数位置变了,就不准确了,比如第一个位置的参数,翻译后位置变到第三个了,如果还是按原来的翻译参数顺序就不对了。个人觉得还是要兼容修复下比较好。
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.
@lxy1151 TranslateFormat
的设计就是format
中的站位符号和values
的顺序是对应的,所以我才说新建一个方法来做不同的事情,设计的逻辑清晰一些。
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.
新增TranslateMap方法?
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.
新增TranslateMap方法?
我个人建议是这样的,至少在原有方法上改不太合适,大家也可以一起来讨论下。
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.
已经修改。
增加了TranslateMap方法
增加了Tm快捷方法
修改多语言替换和参数无关 还原无关文件 处理测试不通过问题 增加了Tm快捷方法 增加了TranslateMap方法
if len(mpStrStr) > 0 { | ||
for k, v := range mpStrStr { | ||
rpKey := ":" + k | ||
result = strings.ReplaceAll(result, rpKey, v) |
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.
- 我不确定
:key
这种模式是否最优雅的替换方式,可以参考其他i18n的转译是使用的什么格式来做的替换。 - 这里直接使用
ReplaceAll
似乎也不是很优雅,例如有两个变量:key1
和:key2
,在替换的时候使用key
则会把它们都替换掉了。
多语言翻译:修复翻译语句参数顺序发生变化时,参数值的顺序还是原来的bug。