Jump to content

Multi Language site (newbie)


barney0o0

Recommended Posts

Hi Folks. Ive looked around the forums, but im still unsure about the correct methods for constructing a multilanguage site.

 

The site will be databse driven, and the database table (in this exmaple content) would be;

 

CONTENT
id     |  Pageid    |  Language    | Title            |  maintext
1      |    1         | En              | English title   | English text 
2      |    1         | It               | Italian title   | Italian text 
3

 

Initially, it would be just 2 languages, however, thinking laterally, this may increase in the near future.

 

Now, questions...

 

What would be the best way to set the default language of the site (italian)

 

 

...something like...

 

<?php
SESSION_START();
if (isset($_GET['lang'])) {
$lang=$_GET['lang'];
$_SESSION['lang'] = $lang;
}
if(!isset($_SESSION['lang'])){
$lang="it";
}else{
$lang = $_SESSION['lang'];
}
?>

 

For the language buttons, is it good practice to use;

<a href="?lang=it">Italiano</a>

to set the SESSION?

 

Many thanks in advance

 

Link to comment
Share on other sites

personally i would store all content into a database table, then have multiple table names: content_en content_fr content_it etc etc.

 

Where a page required content you would add a suffix to all your db queries, eg:

 

$suffix = mysql_escape_string($_SESSION['lang']);

$query = "SELECT * FROM `content_".$suffix."` WHERE `page`='pagename';";

 

you could then add as many languages as you want, just add a new table in mysql (or even copy an existing table and edit to a different language),

 

hope this helps,

 

PS; When take arguments from $_GET/$_POST or $_REQUEST,- in fact anything directly rom the user MUST be treated with extreme caution when you use those variables, notice i used "mysql_escape_string" on a session variable, this should not really be needed as when a session variable is set it should always be checked for invalid characters and patterns. for example if you _know_ you "lang" variable is only going to have 2 characters, you could use "strlen()" to count the characters in the string.

Link to comment
Share on other sites

Cheers Uniflare

 

That seems a good idea....at least it wont overload the tables and adding an additional launguage would seem to be rather straight forward.

 

With reference to the buttons (to select language and ultimatley the session value), would the code on my first post be adequate (or is there a better solution (do spiders follow this))? (sorry i use a combination of handcode and DW!)...if the user presses the button does the page automatically refresh to show the content in the correct language?

 

Thanks alot

 

 

Link to comment
Share on other sites

depends how you handle the query. the html code is adequete its the same type of url i use in all of my scripts.

 

you could do:

 

if($_GET['lang']){

  $suffix = $_GET['lang'];

}

 

then use html as you stated before for the link.

 

 

hope this helps,

Link to comment
Share on other sites

  • 3 years later...

Well users wouldn't necessarily have to be sorted by language, so they could still private message and such. But to view other language's forums I would imagine they should have to change the sites language. Maybe make it a convenient dropdown box or something.

 

If you don't want the change for all forums then put the flag in the forum table instead.

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.