Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I refactor HTML markup out of my property files?

I've recently inherited a internationalized and text-heavy Struts 1.1 web application. Many of the JSP files look like:

<p>
    <bean:message key="alert" />
</p>

and the properties files look like:

messages.properties
alert=Please update your <a href="/address.do">address</a> and <a href="/contact.do">contact information</a>.

with the appropriate translations in N other languages (messages_fr.properties, etc).

Problems:

  1. DRY violation - I have N references to my Struts action URLs instead of 1, which makes refactoring action URLs error-prone.
  2. Mixed concerns - My application's markup is now in more than just my JSP files, making it difficult for a web specialist to tweak the markup (using CSS, etc).
  3. Post-translation markup - Anytime I receive newly-translated text, I must decide what to surround with the <a>...</a> markup. Easy for English but less so for unfamiliar languages.

I've considered adding placeholders in the messages file, like:

alert=Please update your {0} and {1}.

but then the words "address" and "contact information" would somehow need to be localized, wrapped with markup, and passed to my message tag - and I can't see an easy way to do it.

What can I do to improve this?

like image 373
Brian Laframboise Avatar asked Aug 16 '08 16:08

Brian Laframboise


2 Answers

Avoid creating links within long blocks of text. Prefer shorter text that can act as a logically complete and independent link.

Generally, it will lead to fewer problems. Sometimes you have to compromise your UI design to accommodate localization; sometimes you need to compromise your localization process to accommodate the UI.

Any time a developer manually manipulates post-translation strings is a source of potentially expensive bugs. Cutting/pasting or string editing can result in character corruption, misplaced strings, etc. A translation defect needs the participation of outside parties to fix which involves cost and takes time.

Thinking on it, something like this might be less ugly:

<p>Please update your address and contact information.
<br />
<a href="/address.do">update address</a>
<br />
<a href="/contact.do">update contact information</a></p>

...but I'm no UI designer.

like image 172
McDowell Avatar answered Nov 07 '22 20:11

McDowell


One approach that comes to mind is that you could store the translated replacement parameters i.e. "address" and "contact information" in a separate properties file, one per locale. Then have your Action class (or probably some helper class) look up the values from the correct ResourceBundle for the current locale and pass them to the message tag.

like image 34
John Topley Avatar answered Nov 07 '22 19:11

John Topley