Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- site in multiple language
March 10, 2005, 6:05 am
rate this thread
here is vishal.
i am creating a site which will have one option for change language.
once user selects the language i am storing his reply in session
variable. then i want to display the site in his selected language. so
can anyone give me idea that how can i achieve this????
whether i should use database for storing words in different languages
or i should use file for each language.
is there any other better way to solve this problem???????
thxs for your reply in advance.
Re: site in multiple language
The technical side isn't complicated, the syntax/language part is hard.
What you need to create is a database that stores all pieces of text for
each language and retrieve the needed once on each request.
Something like this:
// contains possible languages
CREATE TABLE tbllanguage(
languageid SERIAL PRIMARY KEY,
// contains names for pieces of text
// websitetextname here is just a name for yourself to identify the
// piece of text, it is not used to display.
CREATE TABLE tblwebsitetextnames(
websitetextnamesid SERIAL PRIMARY KEY,
// contains the content for peices of text in a langauge
CREATE TABLE tblwebsitetextlanguage(
websitetextlanguageid SERIAL PRIMARY KEY,
languageid integer REFERENCES tbllanguage(languageid),
websitetextnamesid integer REFERENCES
Suppose you store the languageid in a session.
On a page you need 3 pieces of text (indentified by websitetextsid), you can
look them up in tblwebsitetextlanguage.
If you use languages with difficult characters, be sure to look into all the
encodingtypes. (I cannot help there)
A few tips:
1: It makes sense to retrieve all the needed peices of text needed on a page
in 1 query for speed at the top of the page.
Remember that retrieving 20 rows in 1 query is much faster than 20 seperate
2: You can handle images in the same way. Just let thetext in
tblwebsitetextlanguage contain an image, including the tag: <img
3: I am sure more advanched content management systems have similar
functionality, so if you doubt you can roll this one, have a look at them.
This is just a basic setup.
Hope it helps.