I have a website that I am translating into different languages. I have the content translated and stored in a database. I also wrote, into the php files, different mechanisms that will display the language based on a global define I set high in the code. I am happy with all of this. My question is how do I control this global define?

I currently have a javascript toggle that sets a cookie and then reloads the current page. And every subsequent page just reads that cookie to set the global define. It works very well, however I am running into two big problems. (1) I can't just can't have a url to send to somebody that has the language in it (I could do something like domain.com/forwarder.php?lan=spanish&gotopage=page.php that would set a cookie and then forward, but that's ugly). And (2), search engines can't view the multiple languages since they don't really use cookies and javascript.

So how do I solve this? Does anybody have experience in this? Can you share your experiences?

I'm leaning towards just using the url and dropping the cookie; that seems popular among various international sites I've seen. So I'm guessing the urls would be:

domain.com/page       (for english, equivalent to domain.com/en/page)
domain.com/es/page    (for spanish)
domain.com/fr/page    (for french)
etc ......

Is this a good idea? I will have to go through my code and prepend all my href's with the language code, which might be a pain.

So does anybody have any comments on this? Is this a good plan? Am I neglecting to realize something?

有帮助吗?

解决方案

It's been a long time, but can't you use the $_SERVER["HTTP_ACCEPT_LANGUAGE"] and set it automatically. And prior to writing the cookie for the first time, leave message on the screen in either english or another language in the array asking if this is the correct language, with a drop down of available languages? Once it is selected, store that as default website language.

You can use string constants in global resource files. Have only one website that calls those string constants based on the current language.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top