15.1.06

HTML DB Region Title Dynamic Translation

I've been working at home to build our family web site using OracleXE and HTML DB (2.1). One of the targets for the new design is to support multiple languages dynamically so that whenever user has either English, Finnish or Swedish browser preference the web site should display using that language.


HTML DB has translation capabilities built-in but the functionality wasn't exactly what I was looking for. I wanted the same HTML DB application to support all above languages, not to have multiple languages and multiple applications.


Everything else was doable, I created dynamic content relational tables and the content of the web pages is retrieved from the database using the language preferred.


One problem are was region titles, which doesn't support translatability within the same application out of the box. I am able to print out the region title using application level attributes, so called substitution variables. This is half way what I wanted but there is no language perspective to this. I want to print out the welcome region box title as "Welcome", "Tervetuloa", "Välkommen" dependent on the browser language.


I finally discovered a way to do this. First of all I have to use javascript to do this. Secondly I thought I could use the "navigator.language" variable from the client browser to discover the preferred language of the browser, but this didn't work exactly as I thought. Namely this variable prints out the installed browser language, not the preferred language that user has selected from the browser preferences.


The workaround to discover how to get the "HTTP_ACCEPT_LANGUAGE" -setting took awhile. Finally I got a working Javascript snippet that did the trick with HTML DB:
<script type="text/javascript">var language = '&BROWSER_LANGUAGE.';
if (language.indexOf('fi') > -1) document.write("Tervetuloa");
else if (language.indexOf('sv') > -1) document.write("Välkommen");
else document.write("Welcome")</script>



So the key is to use the &BROWSER_LANGUAGE. -substitution variable to find out the preferred browser language to get the right result.

2 comments:

Anonymous said...
This comment has been removed by the author.
Anonymous said...

Thanks a lot, this is really helpful. Really well for me and I’m not going back to the proprietary guys! If You Need More Information Please Visit us :- eTranslate is an international company specialising in the provision of Internationalization and Globalization Solutions.