What is the trick for multi-language websites (eg you surf in english and when you go to check out and you want other language change it and remain at checkout webpage eg french) ? This can be applied for .mobi sites for mobile phones & pdas sites ?
What is the trick for multi-language websites (eg you surf in english and when you go to check out and you want other language change it and remain at checkout webpage eg french) ? This can be applied for .mobi sites for mobile phones & pdas sites ?
Smart planning and a decent content management and input workflow to boot. There really isn't any magic there.
May be you can have a pages table in database, with fields for each language....
You can maintain the language in a session variable (like $_SESSION['language'] = English)
And you can retrieve the content from the 'pages' table depending on what $_SESSION['language'] is set to...
When user clicks on a click to choose other language, simple change the value of $_SESSION['language']
You mean have for check out page[samely with other pages] a record in db table like:
english,french,italian,german,russian,nederlands
checkout-en.php,checkout-fr.php,checkout-it.php,checkout-de.php,checkout-ru.php,checkout-nl.php
what if I am in checkout-en.php and want to go to checkout-fr.php in what page you change session var and how to choose(and in what page you choose) ?
it doesn't have to be different pages like checkout-en.php,checkout-fr.php,checkout-it.php,checkout-de.php,checkout-ru.php,checkout-nl.php
but it can be something like checkout.php?lan=eng
and the fields 'eng', 'french' in the table 'pages' can be pulled accordingly
by first go to checkout.php?lan=eng after change to
checkout.php?lan=fr how works the change of contain in this second page ?
There are three methods possible (at least theoretically):
1. Create multiple sites: you could have a subdomain for each (for example), and you could use static pages. Nothing complex there. One is in German, one is in Italian, etc.
2. Use a database of stored translations for the phrases (like "hello": fr->"bonjour", it->"ciao", ge->"hallo"), then you query this database for EVERYTHING you output, based on the visitor's language preference. This is like a forum and would be database intensive, that you dynamically generate the text on every page and nothing is hard coded. You'd have a base language and you could write in PHP (etc) something like langout("hello") and the function langout would query for the translations above. A simpler version of this is to have multiple copies of chunks of text and embed them dynamically in a template style (not quite a database, but more complex than option 1).
3. [Currently impossible] You could try actual translation of text on your page using a machine translator. As is right now, even with the best translation available (something like google translate that has taken years to develop and still has errors on even basic phrases), you would just generate a mess (maybe an understandable mess, if you're lucky).
As for using ?lang=fr, that is just a way to tell the page which language to use. There are a number of methods and the best one is to store the choice language in a session variable, account variable, or cookie. Using it in the URL means that you have to check that every time and make all links carry over the value. But you could set it once with ?lang=fr, and you could also use just that method if you are using a method like in (1) where you just have copies of the site and page.php is really just a shell that takes the value of ?lang=fr and then actually grabs page_fr.php and displays that instead.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
This is my way of doing this...
Create a table called 'pages' which should have rows for each page
The fields in each row should be an id, a name which is the actual name of the php file, then a field for every language like eng, fr, ger etc...
So, if you have an order.php, write the html code for order.php in all the languages, create a record with the name order.php and place the code for each language in the corresponding fields.
Note that since language is stored in a session variable, it will not change unless user chooses another language.
I tested the following code by creating a test database and adding some links in the page... and it works good.
Code:<?php session_start(); ########################################################################## //include you database connection code and make the database selection here, in my case it is dbconnect.php ########################################################################## include('dbconnect.php'); //assigns language to session variable iaccording to the url // for eg, if the url is index.php?lang=fr then $_SESSION['language'] becomes french if(isset($_GET['lang'])) { $_SESSION['language'] = $_GET['lang']; } if(isset($_SESSION['language'])) { $language = $_SESSION['language']; }else { //sets the default language to english $_SESSION['language'] = 'eng'; $language = $_SESSION['language']; } ######################################################################################################## /*You can place your html code here which lets user to click on a link to change the language.. or may be a select box... for example <a href = " <?php echo $_SERVER['PHP_SELF'] ?>?lang=fr">View this page in French</a> Note that <?php echo $_SERVER['PHP_SELF'] ?> in the above line echoes the current page... */ ######################################################################################################## $name = strrchr($_SERVER['PHP_SELF'], "/"); $name = substr($name,1); //queries the database and pulls the page content according to the language in $language $query_string = "SELECT * FROM pages WHERE name ='" . $name . "'" ; $query = mysql_query($query_string); if(!$query){ die(mysql_error());} while ($result = mysql_fetch_array($query)) { echo $result[$language]; } ?>
Over the past month or so I've been teaching myself to use the Zend Framework and I've nearly completed a website for a cafe here using it. It is going to be in English and French. I'm finishing up the translation right now. One component of the Framework is Zend Translate. I chose to use the array adapter for it, since it seemed to be the easiest and most straightforward approach.
In your source you would code something like this:
Then in a translation file, if you are using the array adapter, you'll have this:PHP Code:<p><?= $this->translate('On this website you will find a lot of stuff'); ?>.</p>
Then you'd make additional translation files for each additional language you want to use, keeping the base language (english in this case).PHP Code:<?php
// fr.php
return array(
'On this website you will find a lot of stuff' => 'Sur ce site vous trouvez beaucoup de chose',
'More stuff to translate' => 'Plus de chose à traduire',
'etc' => 'etc',
);
You'll still have to figure out how to communicate the requested language to the script, there are a few different ways, but you could use parameter attached to each url .php?ln=fr. You could rewrite your url to include the language, etc.
Now, it is a bit of a struggle to get Zend Framework up and running. And it is all object oriented. And would require considerable work to recode an entire site to use it. You can use Zend_Translate as a stand alone component, and I think it would work exactly the same way, but I've never done it. With that being said, I thought it was useful to let you guys know a little bit about this.
One more thing, the framework has a component called Zend_Cache which is amazingly simple to set up ( at least once you've learned enough to get to the point that it is actually useful). So once your translations are done, you just intergrate your translation files with Zend_Cache and no, or very very very little, performance is lost by having to parse all the translations.
http://framework.zend.com/manual/en/
Last edited by JasonDFR; 04-23-2009 at 06:10 AM. Reason: added link to zend
TO: borris83 Junior Coders
A web page html/server(eg php) whole code, may stored in a field of a database table ?
Bookmarks