如何从属性文件中重构HTML标记? [英] How can I refactor HTML markup out of my property files?
问题描述
我最近继承了一个国际化且文本繁重的Struts 1.1 Web应用程序.许多JSP文件如下所示:
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>
和属性文件如下:
messages.properties
alert=Please update your <a href="/address.do">address</a> and <a href="/contact.do">contact information</a>.
带有其他N种语言(messages_fr.properties等)的适当翻译.
with the appropriate translations in N other languages (messages_fr.properties, etc).
问题:
- 违反DRY -我对Struts操作URL的引用数为N,而不是1,这使得重构操作URL易于出错.
- 混杂的问题 -我的应用程序的标记现在不仅仅包含在我的JSP文件中,这使得Web专家难以调整标记(使用CSS等)
- 翻译后标记 -每当我收到新翻译的文本时,我都必须决定使用
<a>...</a>
标记括起来的内容.英文很容易,但对不熟悉的语言则不太容易.
- DRY violation - I have N references to my Struts action URLs instead of 1, which makes refactoring action URLs error-prone.
- 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).
- 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?
推荐答案
避免在很长的时间内创建链接 文本块.偏爱较短的文字 可以在逻辑上完成 和独立的链接.
Avoid creating links within long blocks of text. Prefer shorter text that can act as a logically complete and independent link.
通常,它将导致更少的问题.有时,您必须妥协UI设计以适应本地化.有时您需要妥协本地化流程以适应用户界面.
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>
...但是我不是UI设计师.
...but I'm no UI designer.
这篇关于如何从属性文件中重构HTML标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!