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 ?
Printable View
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.
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/
TO: borris83 Junior Coders
A web page html/server(eg php) whole code, may stored in a field of a database table ?
yes... you can store html code of whole web page in a field... the type of field should be 'text' so that unlimited amount of text can be stored...
It can be very long, include javascript and css.. It still works without any problem..
you mean in mysql, correct ? TEXT field type need any parameter for Length/Values (in PHPmyadmin GUI DB TABLE creator) ? VARCHAR is not suited and it will return error for page code in a field ?
Yes.. In mysql....
You cannot choose 'VARCHAR' or anything other than 'TEXT'..
You don't have to specify any Length/Values for 'TEXT' but there is no harm in doing so except that it will limit the length to the number of characters you have specified.
VARCHAR is not suited because there is a limit for the number of characters a VARCHAR field can have..
Jason: that approach looks alright, but what you are stuck with then is just two languages. If you want to have three (or more) then that won't work, and if you ever later want to expand your site you will have to rewrite the code.
Of course you could just add another layer to all of it where those are the "fr" sub-array items, but starting off that way will help in the end.
Unless I'm missing something, I'm pretty sure you can have an unlimited number of languages. You are stuck with one base language though.
You'd have your english=>french array file, a english=>german array file, etc, etc. Then you pass the selected language to the zend_translate object and you are good to go.
Now if someone wants to translate from any language other than english, things might get a bit more complicated.
Hmm.... true. But that requires a copy of the English phrases for every language (as opposed to a sub-array of each language for each phrase). Actually, that may work better in some cases. Still, though, you need to include a setup where you will include the correct translation page (fr_trans.php, eng_trans.php, etc) then base it on that.
As for more than one base language, no, that's not very useful. One language as a base makes the most sense. (You could, with complex code, do that anyway, just look for fr->X && ger-->X, where X is the phrase in English and thus fr==ger.)
On a more general note, the big advantage of a phrase-by-phrase system like this (or any variation) is that you are allowed to just default to the english if no french (etc) translation is available for a certain phrase. This way you can have the really important bits of information translated into a language and have the long complex text (like a "welcome" note) in English.
Yeah, but that is the beauty of Zend_Translate. Once the translate object is set up, all you have to do is pass it a language, either based on the user's choice, or one you automatically determine, or a default. And that's it. The object takes care of including the right translation. And with the base language in the source, if a language somehow gets selected that you don't have a translation for, the default is used.
Exactly.
If I save html code in DATABASE field(eg german) then how I can fast change the code in a wysiwyg Editor like dreamweaver ?