开发者

Using custom entities in HTML documents

tl;dr

I'd like to understand if it is possible (and, in case, how well supported) to use custom entities in HTML documents for localization purposes.


What I envision is doing something like this:

<!DOCTYPE html "/locales/en-us.ent">
<html>
  <head>
    <title>&contactus.title;</title>
  </head>
  <body>
    <p>&contactus.youcanreach;<br>123, Example Road<br>12345 Example City</p>
    <ul id="menu">
      <li>&menu.home;</li>
      <li>&menu.products;</li>
      <li>&menu.contactus;</li>
    </ul>
  </body>
</html>

and all entities would be stored in a file (one for each language, en-us.ent in the example above) that gets included at 开发者_如何学Cthe top of the document, e.g.

<!ENTITY menu.home "Home">
<!ENTITY menu.products "Products">
<!ENTITY menu.contactus "Contact us">
...

Eventually this could even be exapnded to HTML fragments (not sure if this is really allowed) that may be useful on all pages (such as headers, menus, etc.; in the example above, the whole <ul> could be such a fragment)

Now, my understanding is that this is theoretically possible in XHTML, but I was wondering if this can be done also in HTML and, in case, how well browsers (and crawlers) would cope.


In theory, it is possible. HTML 4.x (and several previous versions) are SGML applications so you can extend the DTD with new entities.

In practise, every mainstream browser implements an HTML specific tag soup slurper instead of a real SGML parser so you can't do this. This is why HTML 4 has a list of SGML features to avoid and why HTML 5 isn't an SGML application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜