Copy link to clipboard
Copied
Hi
The website I am designing will have two or three different languages.
Is it OK just to use the same database I am currently using but just add extra fields for different languages i.e.
id | contentEN | contentCN | contentFR
like that? and then send the selected language in the URL with $_GET - or would a cookie be better?
I would change the URLs in the htaccess file to make them nicer/more user friendly.
Or is there a better way to do it?
Thank you,
Chris
Copy link to clipboard
Copied
Or is there a better way to do it?
Yes, there is a better way to do it.
Let's say you have a table called 'pages' which contains data specific to pages. Store any language-specific data in a separate table linked by a foreign key.
So the pages table might have the following columns: page_id, main_image, page_type, and the page_content table would have the following columns: page_id, language_id, content.
A third table, called languages, contains five columns: language_id, language_name, language_selected, Language_active, and language_default. See the illustration for administration below.
Then, regarding your urls, they would look something like this:
page.php/page_id=26&language_id=2
You could use htaccess to create 'friendlier' urls, but I wouldn't (Google advises against it)
The problem with using cookies or sessions for the language choice is that it won't be included if someone links to a page.
There are various ways to handle which language will show by default. You can use an IP lookup table to determine which part of the world the visitor is in, but I simply pick the language most visitors are likely to know, so if 90% of the traffic is from Vietnam, we use Vietnamese as the default.