Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the 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.

like image 595
CAFxX Avatar asked Sep 06 '11 14:09

CAFxX


1 Answers

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.

like image 118
Quentin Avatar answered Oct 18 '22 16:10

Quentin