It sometimes makes sense to parameterize localizable strings. For example, in the 404 error page, I need to display a string that looks like:
"Search {site} for {search-phrase}"If this string were in a .properties file, it might actually look like: "Search %S for %P"However, since I need to reference the string from a non-privileged XHTML page, I have to use an ENTITY definition in a ".dtd" file. The "%" character is not legal in an entity definition, at least not as a literal. And, if we want to parameterize an entity, we have to roll our own parameterization scheme anyway. For XHTML files, it turns out the simplest way to do this is to embed XHTML markup in the entity definition, for example: "Search <span id='site'/> for <span id='searchPhrase'/>"It's then trivial to look these elements up using JavaScript and inject the appropriate contents at runtime. This makes for ugly looking strings, but it's dirt simple to implement. It occurred to me the other day, that since you can embed references to other entities inside, you could replace the SPAN markup with something like: "Search ¶m.site; for ¶m.searchPhrase;" A more complete example might look like: <!ENTITY httpFileNotFound.searchSiteFor"Search &httpFileNotFound.paramSite; for &httpFileNotFound.paramSearchPhrase;">where the parameter entity definitions look something like: <!ENTITY httpFileNotFound.paramSite "<span id='site'/>">
<!ENTITY httpFileNotFound.paramSearchPhrase "<span id='searchPhrase'/>">This looks better to me than having the SPAN elements inlined. It would look even better if we could dispense with the "httpFileNotFound." qualification and just say: <!ENTITY httpFileNotFound.searchSiteFor "Search ¶mSite; for ¶mSearchPhrase;">or even: <!ENTITY httpFileNotFound.searchSiteFor "Search &SITE; for &SEARCH_PHRASE;"> What do you think?