What is a better way to create multi-language website?

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Helo,

We are trying to make multi-language website.
Our website itself is based on php/mysql, plus some other things here and there.

Now, we have talked about different ways of accomplishing it and it came down to two options:

1. Use templates.
Basically what this means is that we will create two identical templates, with different texts used depending on the language the user is currently looking at. When we load our pages, we will have to check the current language and load the templates accordingly.
This is similar to what apache's manual has.

2. Use variables.
Similar to option 1, we would define a list of variables which contain the texts we want to use. The variable will then be placed in a single template file. When we load the page, we would read the contents of the variable and then it will be replacing the variables in our template.
This is similar to what phpmyadmin has.


The question is, which do you think is a better approach?

With option 1, we would be less confused when defining the template, as we can see it right away when we create the templates. However, changing one language's template will require us to remember changing the template for other languages, and this is more likely to be missed.

With option 2, changing the template only needs to be done once. However, we need to be sure that our variables contain correct entries. Plus, when the variables grow in size (which is not unlikely), the maintenance may give us headache.


So, which one should we use?
Or, do you have other suggestions as to how to create multi-language website without having to recreate too much code?


Thank you.
-stndn.
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
it kinda depends on how many pages and how many languages

anything more than 5 pages or 2 languages and i'd stick all the content in a database

have 1 table for languages

lang_tbl:
-lang_id
-lang_name

and another table for page contents

pagecopy_tbl:
-copy_id
-page_id
-lang_id
-copy

each page has a copy entry for each language
if a user chooses a language other than the default (english), then set a session cookie
each page will have a page id, query to the pagecopy_tbl to get the content according to the language of the user

if it needs to get more complex (multiple copy entries for a single page and language), you can add a column to the copy table for 'location' or 'area', each entry will still have matching page and language ids

this way, all your copy is in a database. adding languages and pages, as well as editing can all be done via a nice interface. (hint: check out the FCK editor)
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
We're talking about at least 30 pages of generated contents.
For now, we're looking at two languages, but it may grow to add another one.

It seems like you're suggesting we save the contents of a page in the database? Or are you simply implying we save the page_id (which I'm assuming points to a real file) and then load the correct file based on language chosen by the user?

I'm sorry but I'm a little confused...

Let's say for example, we want to make this forum to have english and chinese version.
The forum posts will be in whatever language the user posted in. But the link to 'reply', 'quote', 'top', 'bottom' will be in chinese or english, depending on the user's choice.

Do you mean we just save the translation to 'reply' == 'hui da' and 'top' == 'shang', or we save the whole page and have 'reply' hardcoded for english page and 'hui da' hardcoded for chinese page?


Thank you.
-stndn.
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
page contents would all go into a database

the navigational data could also go into a database, or it could go into files

personally, i'd put it all into a database...but its easy to start out with include files for each language (for the navigational stuff)

when i refer to 'copy' or 'content' i don't mean the entire html of a page, i mean the text portion, the words.

all the html and stuff will come from your template.
if your site is not built yet, you won't really know what kind of templating is going to work best.

build it out in a static format and convert it when its done.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Just a little update.
We have talked about this on our meeting, and the consensus was to use template files for each languages.

So we will have:
/home/web/en/template_1.html and /home/web/cn/template_1.html
/home/web/en/template_2.html and /home/web/cn/template_2.html
etc

which will be loaded as needed.

As for a few common navigational texts (which, unfortunately, gets defined and used outside where our template contents are), they will be loaded from another external file which contains only the variable-to-text translations, with different language in different files.

Let's hope things are not that messy when we actually start the coding...

-stndn.
 

snapper316

Member
Feb 16, 2006
58
0
0
create a data driven website(asp/php/cfm) with proper structure and this becomes much easier than the way you're suggesting as template1 template2 template3

in your URL's you can pass a variable for the langid or establish it through a user profile setting or cookies

Find a higher level(than you) programmer to assist if you are unable to do it in this way, will not be worth it to code it Statically (no offense.....just FYI)
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Oh, sorry for the misunderstanding. I guess I was not clear on my last post.

Yes, the sites will be done in PHP.
What the templates are, are actually the template file containing the "meat" of the page that needs to have different languages, which will be read by the main PHP scripts

Btw, maybe this example will help explain what we decided:

<?php
# Start doing some php code here
# ...

# Check for language to include, be if from profile or cookie or session (most likely) or whatever

# Read any additional language variables
require_once '/home/web/' . $languageID . '/some_include_file.php';

require_once '/home/web/' . $languageID . '/template_1.html'

# Do some other things

require_once '/home/web/' . $languageID . '/template_2.html'

# Do some more work and finish up
?>


No offense taken, so no worries -)


-stndn.
 

hooflung

Golden Member
Dec 31, 2004
1,190
1
0
You really need to do this via a database for simplicity's sake.

Set a default language via a cookie to english, have other languages available through links that will reset the cookie to whatever you provide.

Make your template file switchable via a variable. Something like this maybe? :
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
this will work fine...if you never add languages or pages or edit content.

making it scalable is probably about the same amount of work (if not less)
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Adding pages is a given, adding language we probably can put off if the need is not that urgent.

btw, hooflung, what you attached was actually similar to what we thought of.
The part where you set user cookie depending on the language used, and so on, was shorted by me on this line that i wrote above:
# Check for language to include, be if from profile or cookie or session (most likely) or whatever

Btw, I don't see where the database would fit into this scheme?
Or is this actually something totally different from the database approach that people keep mentioning?

My apology if it sounded like I'm not following everyone's advice. But our brain had some troubles parsing the idea of storing the data in database and then load them later depending on the language.

What we understood was, as long as we have the language code, we can simply load the template having our language texts based on that, right?

So if we get the languageID == 'en', we will simply get /home/www/directory/en/template_file

Isn't it the same as querying the database to figure out which file points to the file above?


We're going go get into the deadly details when we've completed other works that suddenly popped out of nowhere.
Other than that, wish us good luck when it comes time to manage the templates...


-stndn.

Edit:
Is this what the data in the database supposed to look like?
If yes, then that's what we don't understand - where was the difference with our approach?
 

snapper316

Member
Feb 16, 2006
58
0
0
Quick sample

index.asp
page1.asp
page2.asp
page3.asp
page4.asp



that's it. Each page will grab the current LangID and pull from the "data" table accordingly..

so your data table could be like:

pageID
langID
dataHere
moreData
moreInformation

so either

index.asp?langID=4
page1.asp?langID=4
(not recommended as the user could change the #)
Select * from DataTable where langID = url.langID
or store it through a session/cookie etc...

not giving you the entire snippet of code but help on passing/using/storing variables is out there.
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
Is this what the data in the database supposed to look like?
If yes, then that's what we don't understand - where was the difference with our approach?

No.
You put the DATA into the database. The content and markup.
That way you have a couple admin pages to manage ALL content, rather than hundreds of static pages.
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Okay, I'm beginning to see what you are saying now.
So basically what you are saying is that I put the contents of template1.html, template2.html, etc, into the database?
And then generate them on the fly based on the language chosen?

Explaining this is probably frustrating to some of you. But we're learning our way there, and we really appreciate the help and the patience.

Btw, one of our programmers brought up a concern about storing contents inside database.
If we do database query on every page just to generate the static page, won't it be too much overhead?
Of course I can see the easier file management, but is the extra process for sql query really worth it?


thank you.
-stndn.
 

troytime

Golden Member
Jan 3, 2006
1,996
1
0
read queries are ultra fast, no need to worry about it unless your pages are incredibly huge and you're serving millions of pages per day

even on a shared hosting, performance really shouldn't be an issue. just keep the appropriate columns indexed

my companies homepage has 16 queries, with 50ms of sql time
and it is served up about a million times per day
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Okay, then.
I guess we worried too much about performance, which we haven't seen yet but want to be prepared for.
I'll bring this issue up again on our next tech meeting, and we'll see once again if we need to approach our design differently.

Thanks again for all the help and patience.


-stndn.
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |