...
If you have a string that accepts dynamic data, perhaps from a variable, such as "Hello my name is USERNAME, how are you today?" where 'USERNAME' is a variable, you must NOT concatenate strings together within your code. The properties file system contains the facility for placeholders to be set. This is because the way you structure a sentence may not be the same way a user from a different locale structures the same sentence. Using placeholders allows the correct sentence structure to be set for each locale.
Do
Don't do this:
Code Block |
---|
greeting.text=Hello {0}.
configure.link.text=Click {0} to configure this item or {1} to go back.
configure.link.here=here |
...
.1=Hello
greeting.text.2=, how are you today
<fmt:message key="greeting.text.1"/> ${username}<fmt:message key="greeting.text.2"/> |
Do this instead:
Code Block |
---|
greeting.text=Hello {0}, how are you today?
|
Then in your JSP you then provide the fmt:message tag a list of parameters that will be substituted for the placeholders:
Code Block |
---|
<fmt:message key="greeting.text.hello">
<fmt:param value="${username}" />
</fmt:message>
<fmt:message key="configure.link.text">
<fmt:param value="${username}" />
</fmt:message> |
TODO
...