Custom Banner Tutorial
Percentage of Year
Daily News Pick
Animated GIF Archive
Bitcoin Mining. Is it Worth it?
Twitter Bot Examples
Belial - band
Multiple Language Demo
Current language: English
Full text explanation for this page.
That is a question that I see come up a lot... "How do I use multiple languages on one page?" I have written a few answers to explain this, but I thought an actual demo would be helpful.
Because English is my primary language, the only translation on this page that is definitely correct is English. The others are all created using Google Translate. Which means that they are certainly close, but not perfect.
That is the real problem with using something like that to have multiple languages on your pages. You don't know how good the translations are. In the cases where translation is important, you need to have the translations done ahead of time, and kept in a database to retrieve at runtime.
Most of this page will swap correctly based on the language. Except for this next part which shows how it is done. That will stay in English.
How does this work? (not translated). This is a full tutorial so you can build this for yourself.
There are 3 parts to this:
1. Database: Holds a table for pages, tags, and language translations
2. PHP: grabs the cookie value holding the language, and pulls from the database
At page load, the page looks for a cookie containing the index for that language ID. The are:
Or, ID 0 through 4. If there is no cookie, the default is 0 (English).
PHP Code to read the cookie:
The database holds a table with the page name, tags, and language translation for each tag.
The PHP pulls the data by page name, and sets the text for the tags based on the language.
Once that information is gathered, the page can paint out using the variables for the text. Nothing of the content is hardcoded on the page. (look for the PHP tags with the ECHO statement)
In conclusion, if you were to implement this sort of system for your site, the unique identifiers you will need are:
Page name: The page for which you are pulling the data
Tags: Each section on the page that needs a translation Langauge: This demos uses 5 languages. You can do whatever you want with that.
Hope you find this helpful!