最佳翻译实践 [英] Best practice for translations
问题描述
我正在使用JSP编写网站.我想以多种语言提供网站,所以我为我计划支持的每种语言创建了HashMap
,并且正在通过map.get("identifier")
查找文本(当然还有其他一些代码).
I'm writing a website using JSP. I want to have the website available in multiple languages, so I've created a HashMap
for each language I plan to support, and am finding the text via map.get("identifier")
(with some other code, of course.)
我遇到的问题是我以前通过使用format
函数(在许多语言中类似于printf
)解决的,但这是另一种语言.
The problem I'm having is one I've solved before by using a format
function (similar to printf
in many languages), but this was in another language.
具体的问题是,像User performed action
这样的文本可能会以另一种语言出现Action was performed by user
(即,这些术语可能会出现混乱).
The problem specifically is that text like User performed action
may be come Action was performed by user
in another language (i.e. the terms may become out of order).
过去,我做过类似#translate("Welcome to the site, %s!", {"Username"})
的操作,然后使用该语言的format
函数用用户名替换%s
.我可以简单地使用String#replace
,但是我不能像我想的那样做类似#translate("Welcome to the site, %s! You last visited on %s!", {"username", "last visit"})
的事情.
In the past, I've done something like #translate("Welcome to the site, %s!", {"Username"})
, and then used the language's format
function to replace %s
with the username. I could simply use String#replace
but then I can't do something like #translate("Welcome to the site, %s! You last visited on %s!", {"username", "last visit"})
like I'd like to.
很抱歉,如果这是一个错误的解释,请使用PHP之类的内容查找printf
.
Sorry if this is a bad explanation—just look up printf
in something like PHP.
在Java中复制类似内容的最佳方法是什么?感谢您的帮助.
What would be the best way to replicate something like this in Java? Thanks for the help.
推荐答案
不要重新发明.使用JSTL fmt
taglib 一个>.它还支持参数化消息
Don't reinvent. Use JSTL fmt
taglib. It supports parameterized messages as well.
<fmt:message key="identifier">
<fmt:param value="${username}" />
</fmt:message>
另请参见:
- 如何国际化Java Web应用程序?-小型教程
- How to internationalize a Java web application? - a mini tutorial
See also:
这篇关于最佳翻译实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!