Jump to content

Best way to change language


Mutley

Recommended Posts

I've got 3 languages for products on a site in a database (English, German, French). English is the default language.

 

I was considering using variables so when they click say the French flag, it pulls the french language out of the database for that product but this started to get messy.

 

Should I use Cookies or Sessions, how would you do it?

Link to comment
Share on other sites

Id use sessions

 

lets say that you have identical data in 3 tables...1 table for each language.

 

tables

 

english,

french,

german

 

I'd set the Session['lang'] to default to "english"

 

$lang=$_SESSION['lang']

 

then i'd "SELECT products from '$lang' WHERE...."

 

then if someone clicks a button (flag) reset the $Session to the relevant language.

 

That could be one solution.

 

it kinda depends on what table format you have.

Link to comment
Share on other sites

Id use sessions

 

lets say that you have identical data in 3 tables...1 table for each language.

 

tables

 

english,

french,

german

 

I'd set the Session['lang'] to default to "english"

 

$lang=$_SESSION['lang']

 

then i'd "SELECT products from '$lang' WHERE...."

 

then if someone clicks a button (flag) reset the $Session to the relevant language.

 

That could be one solution.

 

it kinda depends on what table format you have.

 

 

ummm.....

 

In that case if one of the table rows will be deleted, everything will go wrong (ID's won't match).

Link to comment
Share on other sites

now...with the greatest of respect....we cant help with that sort of response.

 

You have given no indication of a) how your tables are set up...and b) how you come to your next problems about deletion.

 

Lets start again.

 

Try and be more precise in the environment that you are working and the specific issue(s) that you have.

 

Everything will go wrong is a little but vague...lol

 

 

Link to comment
Share on other sites

Sorry, bit of a brain fart.

 

The database has a table called "products" with fields such as:

id | number | name | description | descriptiong | descriptionf

 

(descriptiong = german, descriptionf = french ;))

 

The language isn't needed to be change else where but, if I wanted a certain page to change as well, that would be helpful, I imagine the session would be easy like variables where it would change what is called?

Link to comment
Share on other sites

i'm doing something similar in my website, i also have seperate tables for each language

 

i'm going to use cookies however, because I want to encourage the user to be comfortable in his own language, so when he revisits the page it will still be in his language, that way he won't have to continue to change the language to his language every time he access the page

Link to comment
Share on other sites

OK, I'll explain it....

 

 

say we have 3 tables, with different languages and the ID (autoincreament value) fileds are the same.

 

example:

 

home - (ID=1, lang=eng)

home - (ID=1, lang=ger)

 

and now, if I want to delete English "home" , ID will change and will not be equivalent to German "home", is that right?

 

so how can I determine on wich page I am?

 

Kindest regards  :)

 

Link to comment
Share on other sites

so you currently echo the results from ['description']?

 

just add a conditional.

 

if ($_Session['lang']=="en") { echo //english description;}

if ($_Session['lang']=="fr") { echo //french description;}

if ($_Session['lang']=="gr") { echo //german description;}

 

PS last post just came up.  Yes if you did that ID's would be a problem....but y would you delete 1 descrition and not all.

 

Anyway youur table is fine.

Link to comment
Share on other sites

I have recently written a multi lingual CMS system. The approach I used was to COMPLETELY SEPARATE the content and other structure. You would have one table containing say your productID, price, etc and a linking languageID which would link to a product_content table containing all the translations and text content for your products.

 

The separate languages would be separated by languageID and products linked to the product_content table by productID. They would be linked using a JOIN SQL statement.

 

So with this approach, you are not needing a separate table for each language, and are not duplicating anything in nice relational design.

 

It works in a similar way for pages and page content. Pages are definated in 1 table, and link to the language in a page_content table via pageID and languageID.

 

Does that make sense? Its basically using a 1:Many relationship for the product:text.

 

You then also need to think about labels, things like "Submit" etc on buttons. For that I had a labels table, which defined labels and the language text for each. You can then lookup the label text based on a keyword using an sql query.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.