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

<pre class="lang-jsp prettyprint-override"><code>&lt;p&gt;
    &lt;bean:message key="alert" /&gt;
&lt;/p&gt;
</code></pre>

<p>and the properties files look like:</p>

<pre><code>messages.properties
alert=Please update your &lt;a href="/address.do"&gt;address&lt;/a&gt; and &lt;a href="/contact.do"&gt;contact information&lt;/a&gt;.
</code></pre>

<p>with the appropriate translations in N other languages (messages_fr.properties, etc).</p>

<p>Problems:</p>

<ol>
<li><em><strong>DRY violation</strong></em> - I have N references to my Struts action URLs instead of 1, which makes refactoring action URLs error-prone.</li>
<li><em><strong>Mixed concerns</strong></em> - 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).</li>
<li><em><strong>Post-translation markup</strong></em> - Anytime I receive newly-translated text, I must decide what to surround with the <code>&lt;a&gt;...&lt;/a&gt;</code> markup. Easy for English but less so for unfamiliar languages.</li>
</ol>

<p>I've considered adding placeholders in the messages file, like:</p>

<pre><code>alert=Please update your {0} and {1}.
</code></pre>

<p>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.</p>

<p>What can I do to improve this?</p>

[{'answer_id': 13239, 'author': 'McDowell', 'author_id': 304, 'author_profile': 'https://Stackoverflow.com/users/304', 'pm_score': 0, 'selected': False, 'text': '<p>Perhaps:</p>\n\n<pre><code>#\nalert=Please update your {0}address{1} and {2}contact information{3}.\n</code></pre>\n'}, {'answer_id': 13250, 'author': 'John Topley', 'author_id': 1450, 'author_profile': 'https://Stackoverflow.com/users/1450', 'pm_score': 1, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 13359, 'author': 'McDowell', 'author_id': 304, 'author_profile': 'https://Stackoverflow.com/users/304', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n  <p>The message message tag API allows\n  only 5 parametric arguments</p>\n</blockquote>\n\n<p>Ah! I blame my complete ignorance of the Struts API.</p>\n\n<p>To quote the <a href="http://struts.apache.org/1.2.7/userGuide/dev_bean.html" rel="nofollow noreferrer">manual</a>: </p>\n\n<blockquote>\n  <p>Some of the features in this taglib\n  are also available in the JavaServer\n  Pages Standard Tag Library (JSTL). The\n  Struts team encourages the use of the\n  standard tags over the Struts specific\n  tags when possible.</p>\n</blockquote>\n\n<p>You could probably do this with the <strong><a href="http://java.sun.com/jsp/jstl/fmt" rel="nofollow noreferrer">http://java.sun.com/jsp/jstl/fmt</a></strong> taglib.</p>\n\n<pre class="lang-jsp prettyprint-override"><code>&lt;fmt:bundle basename="messages"&gt;\n    &lt;fmt:message key="alert"&gt;\n        &lt;fmt:param value=\'&lt;a href="/"&gt;\' /&gt;\n        &lt;fmt:param value="&lt;/a&gt;" /&gt;\n        &lt;fmt:param value=\'&lt;a href="/"&gt;\' /&gt;\n        &lt;fmt:param value="&lt;/a&gt;" /&gt;\n    &lt;/fmt:message&gt;\n&lt;/fmt:bundle&gt;\n</code></pre>\n\n<p>The downside is that this isn\'t valid XML and yanking the values to variables involves more indirection, lookups and verbosity. This is not a good solution.</p>\n\n<p>I don\'t know Struts, but if it is anything like JavaServer Faces (same architect), then there is probably support for configuring a replacement control. I would either replace the existing control with a more flexible one or add a new one.</p>\n\n<blockquote>\n  <p>Anytime I receive newly-translated\n  text, I must decide what to surround\n  with the <code>&lt;a&gt;...&lt;/a&gt;</code> markup.</p>\n</blockquote>\n\n<p>There is no way you should be doing this and I see this as a fault in your translation process (I am an ex-localization engineer and ex-developer of localization tools). The <code>{0}</code> characters should be included in the files that are sent to the translators. The localization guidelines should explain the string\'s context and the meaning of any variables.</p>\n\n<p>You can programmatically validate the property bundles on return. String-specific regex\'s might do the trick. It isn\'t outside the realms of possibility that "address" and "contact information" would swap order during translation.</p>\n\n<p>The simplest solution is to redesign the messages to render:</p>\n\n<pre class="lang-html prettyprint-override"><code>&lt;a href="/address.do"&gt;Please update your address.&lt;/a&gt;\n&lt;a href="/contact.do"&gt;Please update your contact information.&lt;/a&gt;\n</code></pre>\n\n<p>I accept that this might not be a solution in all cases and may have your UI designer spitting teeth.</p>\n'}, {'answer_id': 13381, 'author': 'McDowell', 'author_id': 304, 'author_profile': 'https://Stackoverflow.com/users/304', 'pm_score': 3, 'selected': True, 'text': '<blockquote>\n  <p>Avoid creating links within long\n  blocks of text. Prefer shorter text\n  that can act as a logically complete\n  and independent link.</p>\n</blockquote>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>Thinking on it, something like this might be less ugly:</p>\n\n<pre class="lang-html prettyprint-override"><code>&lt;p&gt;Please update your address and contact information.\n&lt;br /&gt;\n&lt;a href="/address.do"&gt;update address&lt;/a&gt;\n&lt;br /&gt;\n&lt;a href="/contact.do"&gt;update contact information&lt;/a&gt;&lt;/p&gt;\n</code></pre>\n\n<p>...but I\'m no UI designer.</p>\n'}]
['https://Stackoverflow.com/questions/13225', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1557/']