Context:
I'm in the design phase of what I'm hoping will be a big website (lots of traffic, lots of users reading and writing to database). I want to offer this website in the three languages I speak myself (English, French, and by the time I finish the website, I will hopefully have learned enough Spanish to offer that too)
Dilemma:
I'm wondering how I should go about offering these various languages (and perhaps more in the future).
Criteria:
Many methods exist for designing multi-language websites. I'm looking for the technique that will result in a faster browsing experience for the user.
Choices:
Currently, I can think of (and have read about) the following choices. They are sorted in order of preference up to now.
Store all language-specific strings in a database and fetch the good one depending on prefered-language (members can choose which language they prefer), browser-default-language and which language is selected during the current session, in that order.
Pros:
- Most of the time, a single test at the beggining of the session confirms which language to use for the remainder of the session (stored in a SESSION variable). Otherwise, a user logging in also fetches the right language and keeps it until he/she logs out (no further tests). So the testing part should be pretty fast.
Cons:
- I'm afraid that accessing the database all the time would be quite time-consuming (longer page load for the user), especially considering that lots of users could also be accessing the database at the same time for the same reason (getting the website text in the correct language), but also for posting comments and the such.
- Strings which include variables (e.g. "Hello " + user.name + ", how are you?") are harder to store because the variable (e.g. user name) changes for each user.
- A direct link to a portal for a specific language would be ugly (e.g. www.site.com?lang=es)
Store all language-specific strings in a text file and fetch the good one depending on prefered-language (members can choose which language they prefer), browser-default-language and which language is selected during the current session, in that order.
Pros:
- Most of the time, a single test at the beggining of the session confirms which language to use for the remainder of the session (stored in a SESSION variable). Otherwise, a user logging in also fetches the right language and keeps it until he/she logs out (no further tests). So the testing part should be pretty fast.
Cons:
- I'm afraid that accessing the text file all the time would be quite time-consuming (longer page load for the user), especially considering that lots of users could also be accessing the file at the same time for the same reason (getting the website text in the correct language).
- Strings which include variables (e.g. "Hello " + user.name + ", how are you?") are harder to store because the variable (e.g. user name) changes for each user.
- I don't think multiple users could access the text file concurrently, though I may be wrong. If that's the case though, every user loading a page would have to wait for his/her turn to access the text file.
- Fetching the very last string of the text file could be pretty long...
- A direct link to a portal for a specific language would be ugly (e.g. www.site.com?lang=es)
Creating multiple versions of the website in seperate folders, where each version is in a different language.
Pros:
- No extra-treatment is needed for handling languages, so no extra waiting time.
Cons:
- Maintaining the website will be like going to school: painfull, long, makes you stupid after doing the same thing over and over again.
- ugly url (e.g. www.site.com/es/ instead of www.site.com)
Additionnaly, the coices above could be combined with one or more of the following techniques:
Caching certain frequently requested pages (in a singleton or static PHP function?). Certain sentences could also be cached for every language.
Pros
- Quicker access for frequently-requested pages.
- Which pages need caching can be determined dynamically, with time.
Cons
- I'm not sure about this one, but would this end up bloating the server's RAM?
Rewritting the url could be used for many things.
- A user looking for direct access to one language could do so using www.site.com/fr/somefile and would be redirected to www.site.com/somefile, but with the language selected beign stored in a session variable.
Pros
- Search engines like this because they have two different pages to show for two different languages
Cons
- Bookmarking a page doesn't mean you'll en up with the right language when you come back, unless I put the language information in the url (www.site.com/somefile?lang=fr)
A little more info
I usually user the following technologies to make a website:
- PHP
- SQL
- XHTML
- CSS
- Javascript (and AJAX)
This being said, if a solution requires that I learn a new language or something, I'm very open to doing so. I have no deadline for this project and I do intend to learn a lot from doing it!
Conclusion:
What I'm looking for is a method that allows me to offer multiple languages while not increasing page load time and not going crazy when trying to maintain the website. If you guys/gals have other ideas I should consider, I will try adding them to my list. Another possibility is that I'm overdoing this. Maybe I won't gain enough time with these methods for this all to be worth it, I just don't know how to verify if I need to worry about this or not.. so if you have any ideas for that, it would also help me.