0

i want to put the link for other language...if i click on that language the site will convert to that language...plz can anyone help me...its urgent...
thnks in advance...

2
Contributors
3
Replies
24
Views
3 Years
Discussion Span
Last Post by diafol
2

its urgent...

Not to us it's not. You can use a number of approaches:

1) PHP array items
2) GETTEXT

For beginners, the first method would probably be the easiest.

All you do is create files like these...

lang/en.php

<?php
    $lang = array(
        'hi' => 'Hi, how are you?';
        'bye'=> 'Bye!';
    );
?>

lang/it.php

<?php
    $lang = array(
        'hi' => 'Salve, come stai?';
        'bye'=> 'Addio!';
    );
?>

Have a link to set the language, somthing like this:

session_start;
$defaultLang = 'it';

if(isset($_GET['lang']) && in_array($_GET['lang'], array('en','it')))
{
   $lang = $_GET['lang']; 
}elseif(isset($_SESSION['lang'])){
    $lang = $_SESSION['lang'];
}else{
    $lang = $defaultLang;
}

$_SESSION['lang'] = $lang;
require "lang/$lang.php";

Then...

<p><?php echo $lang['hi'];?></p>

If you want to use GETTEXT see here:

http://diafol.blogspot.co.uk/2013/01/php-localization-with-gettext-on-windows.html

http://diafol.blogspot.co.uk/2013/01/creating-pot-files-in-poedit-for.html

http://diafol.blogspot.co.uk/2013/01/supporting-xgettext-on-windows-from.html

http://diafol.blogspot.co.uk/2013/03/gettext-issues-fix-with-php-gettext.html

Edited by diafol

0

i don't want to convert a single page to other language...want my website to other language...

Edited by hriti: spelling mistake

0

That will do it. But you must provide translations whatever you do. The 'session' keeps track of the language. You could even add a cookie read/write for users that return - so that the site remembers their language.

An alternative method would be to store multiple versions of your site in different folders - but that's daft IMO.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.