1. PresentationI've been looking for the best way to have my WebSite support multiple languages. Most of my pages are straight standard HTML, but I also use PHP for dynamic content or computation. I found several solutions bases on PHP :
It seemed that solution 1 was overkill for the Database. At least that is what people said. Also, having a specific piece of code in each page to retrieve the texts did not appeal to me. Solution 2 was pretty good, but I had to convert all my HTML files to PHP, and include a parameter to switch between the languages. Finally, solution 3 was mentionned for 'small websites', but I wouldn't recommend it even for the most tiny of sites :) 2. ConceptWe need to realize that often, we use PHP files for content that could be provided easily using standard HTML pages. The database requests will always provide the same results, giving an identical content for the page. Having your web server work only to provide again and again the exact same page seems silly enough. So we'll try to make the best of solution 2 with an automated process that will save us the work of going with solution 3.
On the diagram above, you can see how the application is designed. You have one set of pages (Your Website) that we will call "Raw HTML" files. These files are not language dependant, and will contain no text : They will only have references to translations. On the other side, you will have one XML file (or anything that suits your needs) with all the references translated for each language that you wish to support. Once your page and translation are ready, a simple program (Here called 'Site Translate') will create a set of pages for each language. This way, your website will not have any overhead by supporting multi-languages, besides the time required for the translation of course :) 3. Prepare your siteI could end up this article right here and leave the rest as homework for the reader, but since I have implemented this process for the site you are currently viewing, I can at least publish what I have done :) Here's how I did it. Sample Raw HTML file : Sample XML file : As you can see in the sample file, I used the following syntax for my tags : "{@Tag@}". This is to ensure the tool will not replace parts of the page that are not intended to be. This is all that needs to be changed in your HTML file. The XML file is a bit more complex, but not by much. We have a section to describe which languages we support ( 4. DeployThis is definitely the easiest part. Using the Site Translate tool (.NET has to be installed on your computer), you simply need to identify your raw HTML files. For each one, the tool will look for the corresponding XML file and start creating the final pages for each language. I used the following convention :
5. More...Things you need to be aware of :
If you wonder if the tool is reliable, well this whole website has been generated with it. Have fun ! |