Jump to content

Language change with php


Gruzin

Recommended Posts

Hi guys,

 

I'm making a new web site, so there should be 2 languages: English and Russian.

 

say I have a page: index.php?lang=ENG&id=3 - about us

 

and when user clicks on russian version, page should display russian content of ABOUT US page and not homepage as it is now.

 

Hope my example was helpfull, and if not please tell me about that...

 

Thanks,

George

Link to comment
Share on other sites

You might want to consider a different way of passing the language around from page to page, possibly with sessions.  It's a little bit cleaner.

 

Secondly, you have three sets of information which could potentially need to be in multiple languages.

 

There's hard coded content, such as an actual .html file displayed by the site.  For these you'll want to separate the files into directories where the base directory defines the language.  i.e:

en/home.html <- english

sp/home.html <- spanish

du/home.html <- dutch

 

There's program output, which is basically strings of text in response to events.  For these you'll want to use a string look up table:

$lookup['en']['error'] = "Sorry, an error has occurred processing your request.";

$lookup['sp']['error'] = "actual spanish";

 

Then there's potential database data.  Not sure how to deal with that.

 

I'd look up programming and internationalization through google.

Link to comment
Share on other sites

You may be better off with files rather than a database. Only because of the different charactor sets between the 2. Can try it but not sure if it will work or not. If you do want to do it you may have to have 2 tables with different datasets and use a session to select which table the translation comes from.

 

Ray

Link to comment
Share on other sites

You may be better off with files rather than a database. Only because of the different charactor sets between the 2. Can try it but not sure if it will work or not. If you do want to do it you may have to have 2 tables with different datasets and use a session to select which table the translation comes from.

 

Ray

 

 

Thanks a lot! I'll give it a try....

 

Regards,

George

Link to comment
Share on other sites

I agree with sessions. And I tend to see something like this in many scripts: have a file with the language definitions. Like this:

 

english.php

 

$lang['pleaselogin'] = 'Please enter your username and password';

$lang['badlogin'] = 'Invalid username or password';

 

russian.php

$lang['pleaselogin'] = 'Russian for please login';

$lang['badlogin'] = 'Russian for bad password';

 

Then at the top of every file, check the session. If the language is English, include english.php. If the language is Russian, include russian.php. Then, when you display text, echo something from the $lang array. Then you can always change the text or add more languages later.

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.