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...

Recommended Answers

All 3 Replies

Member Avatar for diafol

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

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

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.