IJDb ...Resources ...Community ...Search ... |
Creating multilingual websitesColin E. - 4th November, 2004. [Page 1] [Page 2]This article describes the development and usage of an Object Oriented solution for dynamic, multilingual websites, SiteTranslator. If you want to cut the waffle you can download it now:
PrefaceDuring the past couple of years I have spent countless hours developing this site (the Internet Juggling Database). In this time I have learnt a lot about PHP, HTML, Java, mySQL and whole host of other technologies. Some of the code behind this site is good and some is bad. I have decided to share my learning experience by publishing some of the code and techniques I have learnt and developed. Although I hasten to add, I will only be sharing the good bits! This article describes the technique I used to create a dynamic multilingual website. If you find it useful, please let me know. It will encourage me to keep on sharing. IntroductionWhile it is true that the English language is the most commonly used on the internet, I was personally surprised that is was not more dominant. The English language accounts for 38.3% of internet use, i.e. 38.3% of internet users browse sites written in English. For a full break-down of internet language use have a look at the statistics found on the Global Reach site. When I first developed the Internet Juggling Database (IJDb) my aim was to create a community site for anyone who had an interest in juggling. The choice of language was pretty obvious, I am British, and like most Brits I speak English ... only English. So the when the IJDb first went online the content was written entirely in English. The dynamic nature of the site ensured that after being online for just a year, it was getting quite large. I put a little comment in the online 'to do' list saying that it would be nice if the site could be translated into other languages, although I wasn't really expecting anyone to volunteer for such a mammoth task. However, sure enough a kind soul stepped forward and volunteered to translate the site into German. Now that I had a volunteer I just had to find a way to enable the translations to commence. Not an easy problem. The problemThere are numerous multilingual websites on the internet, most large multi-national companies have websites available in a few different languages. However, the most of these sites provide links for different languages, following a link takes you to a different document for each language. I found this technique to be quite undesirable due to the problem of maintaining these static documents, a time consuming process with the developers having to synchronise separate copies of the website. Furthermore, considering the dynamic nature of my website, I was loathe to create a static copy just for the purposes of translation. What I needed was a dynamic solution. Multilingual software is certainly not a new thing, and existing techniques used for offline software can be used online. A brief overview of the possibilities can be found in this article on Native Language Support. However, I did't find a solution which had all the features I required, as did the author of this article. In summary what I wanted was:
The only way I was going to meet these needs was to create my write my own system. The SolutionMost of the text displayed on any website resides within HTML, although it may sit next to dynamic PHP code. The first step in my solution was to remove the static text and place it in a table within the database, with each block of text being identified by a short text key, for example 'frontpage_introduction'. All that is left to do is add a little bit of PHP code to retrieve the text that this key refers to:
<?
//displays the text for the key 'frontpage_introduction'
echo GetText('frontpage_introduction');
function GetText($key)
{
//NOTE: code to connect to the database has been omitted
$strQuery = "SELECT Description FROM EnglishText WHERE Key='$key'";
$myrow = mysql_fetch_array(mysql_query($strQuery));
return $myrow["description"];
}
?>
With the text now stored in the database it is now possible to start serving localised text. In the above example the English text is stored in a table 'EnglishText', a second table can be created, 'GermanText' with the same structure, i.e. short text keys associated with the larger text descriptions. The above code then needs to be modified to query the text-table for the visitors language preference. The above example is modified as follows:
<?
//displays the text for the key 'frontpage_introduction'
echo GetText('frontpage_introduction', $language);
function GetText($key,$language)
{
//NOTE: code to connect to the database has been omitted
//provide the German version of this text
if ($language == "de")
{
$strQuery = "SELECT Description FROM GermanText WHERE Key='$key'";
$result = mysql_query($strQuery);
//determine whether this text key exists in the German table
if (mysql_num_rows($result)!=0)
{
$myrow = mysql_fetch_array($result);
return $myrow["description"];
}
}
//provide the English version of this text
$strQuery = "SELECT Description FROM EnglishText WHERE Key='$key'";
$myrow = mysql_fetch_array(mysql_query($strQuery));
return $myrow["description"];
}
?>
In the above example, if the German version of the text is preferable, the German table is queried first. If the text is not present in the German table, the default English text is returned. This will allow the German translator of the site to translate the text gradually, with visitors browsing in German still being able to see the entire site, i.e. they are not restricted to the German content. Of course the above example is a little simplistic, the visitor language should really be stored as a session variable and determined dynamically (this can be done by inspecting the $HTTP_ACCEPT_LANGUAGE variable as described in this article, although the illustrated approach is a little lacking in that it does not deal with multiple language preferences). Also, with a little bit of imagination the above example could be developed further to query a number of databases with support for a whole range of languages. One of my main requirements was to allow translators to log in to the site and edit the text 'live'. I acheived this by making an addition to the above GetText function which detected whether the visitor was logged in as an editor, if so, a litte 'translate' link would be output next to the block of text. This links lead them to a special translation page where they can input the translated text in their own language. With this dynamic method of translating my website implemented I am happy to say that numerous people volunteered to translate the site into different languages. My website is now available in 10 different languages, with another 4 under development! A few years after developing this translation system I found that on occasions people would ask how it worked and whether they could use the system on their own websites. This encouraged me to totally re-write the system using Object Oriented techniques allowing for a more modular and flexible system which should be easy to 'plug-in' to any website. Rather than expand the above examples into a fully functioning translation system, the next page of this article describes my final solution, SiteTranslator. [Page 1] [Page 2] view in thread mode or date mode post a new message2nd Mar 2010 Могу помочь сдел Могу помочь сделать на русском. Обращайтесь http://vpotolok.com.ua 18th Sep 2009 How Long Hi, i would just like to know how long it will take me to learn XML, i'm a girl with basic html skills, so could anyone tell me if there is any courses to learn XML on the net? Thank in advance... Sarah Payday Agency http://www.paydayagency.co.uk 19th Jan 2010 Re: How Long Thanks, very useful --------------------- nuoc hoa, nước hoa, my pham, mỹ phẩm , trang diem , qua tang, quà tặng, dien dan nuoc hoa 7th Nov 2004 Can you send me some more exam... Can you send me some more examples? (a page with a link and the database content .sql file) I would be very happy!! THANK YOU 31st Dec 2009 Re: Can you send me some more exam... Does exactly what you want it to do! Easy to use and makes all translated content easy to manage. Have a look at my company's site to see it in action with English, German & Chinese: www.libs-international.com Thanks :) ___________________________ tuyen dung | tim viec | viec lam http://ungvien.com.vn/employer/main.htm 9th Apr 2007 database time To those writting about long times extracting data from data base to view page, I have not had any delays in showing files and I have a lot of tables in data base. The only time delay is when menu loades in edit mode, and because I have so much in my database it can take upto about 2 minuets to load menu and database is growing, so to elimanate load time there I mearly set the menu side to open (there are 2 sides on main edit page, one listing all tables in menu and other the page section they click to edit-translate) in seperate window with a link to it in main edit page were the menu side use to be, and now when editors edit then translate page file the menu does not load at the edit page (loads in seconds) (when they refresh updates the edit page reloads allmost instantly (no menu refresh time), Also advantage is they do not need to access menu and I prefer not giving them access to it, as they can tell if page needs updated by reading the page they are on. As I want this program available for many people to edit their own pages (not just languages) so that it would work as a wysiwyg type editor for them no matter what language. I am still working on a solution to that so abc company can only edit their page(s). For now all I have done is disable the links to other pages when in edit mode so they do not go to other pages and could be a security issue with one bad apple and still working on that, any idears would be appreciated. Trabob www.trabob.com 18th Sep 2009 Re: database time Why would this matter. Which script are you talking about mate? Erdy Payday Agency http://www.paydayagency.co.uk 14th Nov 2009 Re: database time Thanks for your post http://www.nuochoa4u.com 30th Oct 2006 A working site using this script I installed the script to one of my sites at http://www.trabob.com/translate.php It seems to work good, and it seems to be attracting some viewers from other languages. The biggest problem I have is some languages Greek, Russian, oriental, need special codes in mysqyl codes and I have not figured out which codes to use for them in mysqyl. Greek is one that I need to reset my browser view for each page and not sure if codes are wrong in mysqyl or if it is a problem in browser (internet explorer 6.0) I set it up somewhat different were the only flag of language it is using shows on each page with a link back to main translate page to change it, as the flags take to long to load if all on every page. I plan on adding about one language each month (12 per year) but can't add languages that use something different then Latin unless I can find the correct codes for mysqyl. Comments - suggestions appreciated Thanks Bob 4th Nov 2009 Re: A working site using this script If you want to use multi-lingual charsets, simply change the doctype so instead of iso-3166 it reads utf-8 29th Sep 2009 Re: A working site using this script Thank you for sharing. It is useful for my site. Ngan hang 27th Nov 2008 Re: A working site using this script If you want to help enhance your website online then join our project at http://www.wordbricks.com 8th Jul 2009 Re: A working site using this script www.travel2ohrid.com 9th Apr 2007 Re: A working site using this script I have since found the way to get the browser to recognize the language code by inserting # "> and finnally figured out that in the configure file between "" in one of the spaces is were the charset goes, as there is no info to tell you that on that file, and the greek language appears to correct when in the greek language, at least with IE browser, in case anyone else runs into that problem. I haven't tried the russian language yet charset "ro18" or something like that as database didn't seem to like that code (scrambled it) Trabob 9th Apr 2007 Re: A working site using this script trying code again < META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=" > 7th Sep 2009 Re: A working site using this script Thanks for the wordsbricks link... very useful. Chris @ London Tours 7th Sep 2009 Re: A working site using this script Thanks for the wordsbricks link... very useful. Chris @ London Tours 7th Sep 2009 Re: A working site using this script 5th Mar 2009 Re: A working site using this script 29th Sep 2009 Re: A working site using this script thanks for your post http://www.muabanperfume.com 26th Mar 2009 Re: A working site using this script 12th Aug 2009 Source code of multilingual website Hello friends, I have created one website with 2 languages: 1. English 2. Polish here when i open the site and see the page view source, then it shows polish characters like below Wydarzenia Moje Wydarzenia Dodałem/am Imprezy Społeczność Koncerty Darmowe Wydarzenia Dodaj Imprezę if you take a close look of above code then you will fine a character starting with ... which is a polish character stored in database. it shows correctly in browser but in source code i can see this. I want to show a character as it is in view source as like in browser. can anybody help me of this 2nd Mar 2009 HELP! I have the PHP files uploaded and installed but I cannot figure out how to put a link on my page and have the script translate that page. Do I need an .htaccess file. If so , what do I put in it? The script works on the demo/index.php file. I can use the /demo/?lang=de extension to translate into german. But I cannot use this with any other files, such as /demo/test.html?lang=de or http://www.mydomain.com/?lang=ru I must be doing SOMETHING wrong. Help! 9th Oct 2008 reTHINK! Multilinguism Hello, thanks for the original article, I am going to use it. Some contribution to the general issues here. THINK! The Owner of a site might want multi languages in order to reach and serve more people. The Owner may therefore provide the top preferred language the browser of the Viewer is indicating. This completely satisfies the Owner reasons just mentioned. Actually, from the Viewer's point of view, the site is a ONE-language site! However, this does in no way imply that the Owner needs to provide a *choice* to the user. To provide a language choice to the Viewer the Owner reasons just mentioned are not relevant. To provide such a choice additional reasons are needed. BUT: why would a Viewer want to see the SAME site in several languages? I can see several reasons, like its is *interesting*, like wanting to *compare phrases* , like *viewing with someone* native in another langaue, like the language preferrence of the browser is wrong for a particular user (e.g. in an internet shop). But does a Owner have to deal with this possibility? None of these reasons seem to me SUFFICIENT reason for an Owner to want to provide such a choice. Examples: Wikipedia sites are said to be multi-language, but they are not! Each change of language brings you to a different site alltogether, different contents, different lay-out, depending on the country. So, WIKIPEDIA sites are ONE-language sites. Google's opening site IS really multi-language, and it shows the same content. Again, why would one NEED to change language to see the same content? Google is offering only one (1) choice: when I go to the site, it is in my langauge, and it offers to me the choice for the english language. That is nice, but in no way I *need* that. Strange, I cannot come up with a *sufficient* reason for a Owner to provide a language *choice* to the Viewers. May be some language teaching site would HAVE to provide a choice? Please help me out! François 13th Oct 2008 Re: reTHINK! Multilinguism The reason for people wanting to change languages is that we may want to have a default language on our PC -Spanish, in my case- but we do not necessary want sites to pick it up automatically. I hate it when Microsoft assumes that I want a Spanish interface and Spanish content, just because I usually type in Spanish on my PC. I hate it even more when Google and other sites assume that I want German just because I connect to the web from Luxembourg. The other reason is that more often than not the translations are appalling; I am far less upset by bad original English or French than by bad translated Spanish. I want to be able to choose myself. Isabel 21st Oct 2008 Re: reTHINK! Multilinguism Also, I may be looking at the site from a kiosk, library, or other public computer. That computer may be set to English, but I'd like to see the site in Spanish. --Al- 26th Sep 2008 Creating Multilingual Websites This is a very comprehensive article and great for people who have strong technical skills. However, the market for multilingual websites does not provide a cheap solution for those who cannot do it themselves. There is a new service called Web247.net which has just been released and fills this gap in the market. If you are looking to set up a multilingual website and don't want to pay for a designer, please visit www.Web247.net. Sarah Diggins Managing Director Web247.net | ||
| 0.53 seconds | |||
I am an MSC in computing with e-business, and my thesis is about design of multilingual web application. I have designed a new method of structuring multilingual website that is maintained centrally and presented locally. This web site is based on the design of dynamic web application in which separates its dynamic content (database) from static content (interface design). The website is linked to a single database, which contains two data tables. First table which is the main table is to store numeric information (e.g. product quantity, price, date, and act), while the second table which is a dictionary, is to store other information (product name and description) in all languages included. The technology used in this website is J2EE with its JSP, plus XML and XSL technologies. The JSP imports the Stylesheet that includes the layout and decoration. I have modified the “Java importing” function to be able to import more than one Stylesheet within more than one language. As a result, the website is working in tree languages (English, Arabic, and Chinese). This website includes some e-commerce functions such as buying and selling product online.with this method to add a new language you need to include only two files per language instead of creating a sub-site for each language.
Not, this project will be published after my graduation, which will be very soon.
Thanks