Sasha Borodin
Sasha Borodin

Reputation: 313

Pattern to internationalize links in JSF

I want to internationalize the following content:

Click here to view our privacy policy.

here is a hyperlink. Here is how I currently go about it:

#{msg.footer_privacyPolicy1}
<h:outputLink>
    #{msg.footer_privacyPolicy2}
</h:outputLink>
#{msg.footer_privacyPolicy3}

msg is a ResourceBundle registered in faces-config.xml, with the following contents:

footer_privacyPolicy1 = Click
footer_privacyPolicy2 = here
footer_privacyPolicy3 = to view our privacy policy.

I think there must be a better pattern to achieving this. Here is what I don't like about my approach:

Is there a better approach to internationalizing content that is necessarily partitioned by the mechanics of presentation markup?

Upvotes: 4

Views: 115

Answers (1)

BalusC
BalusC

Reputation: 1108852

JSF utility library OmniFaces offers <o:param> for the exact purpose.

footer.privacyPolicy = Click {0} to view our privacy policy.
footer.privacyPolicy.link = here
<h:outputFormat value="#{i18n['footer.privacyPolicy']}" escape="false">
    <o:param><h:link outcome="privacyPolicy" value="#{i18n['footer.privacyPolicy.link']}" /></o:param>
</h:outputFormat>

On contrary to <f:param>, it's capable of encoding child components as parameter value.

Upvotes: 4

Related Questions