phpmultiple-languages

Website with multiple languages


So I'm trying provide my site in multiple languages.

I'd like to have an option to change the language on the page without changing the url. (Just like YouTube)

My question: How can I provide my website in multiple languages while keeping the url the same? And also have each language indexed by search engines

Here's my current idea:

My current idea is to have each page look for a language variable (will be set in either a cookie or user setting)

Then from that variable, load a file that has an array with the text of the corresponding language.

Now I just pull values from the array and put them inside of elements.

For search engines, I can set a get the language option as a get variable.

But, this method may not be the best


Solution

  • You store the language in a cookie. Xou are right there. Then you load a file based on the language. This file is something like XML or YAML.

    XML (english):

    <string id="title">My Page</string>
    

    XML (german):

    <string id="title">Meine Seite</string>
    

    XML (klingon):

    <string id="title">DutlhHo'</string> <!-- not actually klingon -->
    

    You now just parse this.