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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With