Jump to content

Two Langauges, One Site...


gc40

Recommended Posts

Greetings all,

I have made a CMS for a site where the admin can update text content on the home page....

 

They login to the admin panel and enter a title, and the body.

 

However, the client wants to offer two languages now. One English, and one French..

 

Therefore, I made the database changes by adding one extra field called body_french and changed body to body_english...

Now the admin enters the body for both english and french...

 

The problem comes when I display the database information on the home page.

How should I allow the client to select between English and French?

 

Should I use sessions? Or should I use a simple PHP If else fucntion?

 

Also, if I use sessions, can someone direct me how to start? I have never used sessions.

Link to comment
Share on other sites

your over working yourself here

 

I'm going to explain a much more generic solution to you that will save you a bunch of work when they want German Spanish and simplified Chinese also

 

this is one way to do it

 

1) Make all your dynamic language areas into a database

2) Send this data through a translator (such as google translator) before echoing it out

3) Display data normally

so it be like

<?php
$string = "Hello World"
$string = lang_trans($string);
function lang_trans($string){
if(!ISSET($_SESSION['language'])){
  $lang = DEFAULT_LANG;
}
else{
$lang = $_SESSION['language'];
}
//Now send the string and language to go to to your translator and get it returned as $string
return $string
}
?>

 

The way you translate is up to you some people have develop php string langauge translator, but you can probably use cURL to send data to google and get it translated back (this might be slow)

 

Alternatively you can store statics in the translations, but this will be very space consuming if you expanding beyond 2 languages.

 

But to answer your question a session is the best mode (dual it with cookies if you want a stronger method)

 

Another way to do it is on every page load simply replace the entire page with the frame removed google translate version of it (very common solution and practical)

 

however this only works if your CMS is set up to display the page dynamically.

Link to comment
Share on other sites

What I would do if I were you is have a function that is put on a page that is required() in all pages. The function would be like so...

 

<?php
session_start();
if(empty ($_SESSION['lang'])){
if(!empty($_GET['lang'])){
$_SESSION['lang'] = $_GET['lang'];
}else{
echo '<form id="lang" name="lang" method="get" action="'.$PHP_SELF.'">';
echo '<select name="lang">';
echo '<option value="en">English</option>';
echo '<option value="fr">Français</option>';
echo '</select>';
echo '<button type="submit">Submit</button>';
echo '</form>';
}}else{
$lang = $_SESSION['lang'];
}
?>

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.