Jump to content

Suggestions on Multi-Lingual Site?


brusq

Recommended Posts

Hi
I hope this is the right place to ask this question, I am trying to do a project with PHP+ MYSQL. The site will be a online real estate agency. I would like to hear from experienced users on how to implement the contents in 2 different language. e.g.English -Italian ?

kind rigards
Link to comment
Share on other sites

It's not difficult, just tedious. This includes alt attributes and other "non visual" text.

You need to identify each and every text field on the site. Then instead of putting the text directly into the codet that displays the page. For example instead of this:
[code]echo "<a href=\"contact/getinfo.php\" title=\"Get Contact Info\">Contact Us</a>|;[/code]
You would have something like this:
[code]echo "<a href=\"contact/getinfo.php\" title=\"$getContact\">$contactUs</a>|;[/code]

Then you need to decide how you will create the variables. You could either store all the text data in the database with the variable name, page it's used on and the english and Italian text. Then on each page you will need to do a query to call the appropriate text based upon the page and the user's language. Or, you could simply use language files where you have two files (one english & one italian) and you just include the correct one. You could have language files for the entire site or separate ones for every page. Having one for the entire site makes sense if you have a piece of text that is exactly the same on many pages - then if you have a change you can make it one. You would have to decide based upon the size and complexity of your site.

Lastly, you need to create the method for the user to choose a language and to save that choice. If you have a login system you could save their choice along with their login info to the database. Otherwise, you would need a cookie. You could probably do some additional functionality to pre-select the language based upon IP.
Link to comment
Share on other sites

You could use a language directory, and in the directory you have some php files..

And each file (Named its language ie: english.php) will have aload of DEFINES..
So you can have say

DEFINE("WORDONE", "DIFFLANG")
DEFINE("WORDTWO", "WORDTWOIN A DIFF LANG")

That way in your main files you have just to echo WORDONE, and it will display its value, now to set up to choose the language you would have say...
(BTW: To change the lang use GET in urls... mydomain.com/index.php?lang=french)

$language = $_GET['lang'];
$langfile = "/languages/" . $language . ".php"
if (file_exists(/languages/$language.php){
require("$langfile");
} else //if GET lang not set just use ENGLISH as default...
require("/languages/english.php");
}

And then you just have to put all words that are defined as CAPS.. and they will come up in the languages....

If you dont understand that please post and i will try go more into debth..
If its the code you dont understand, have a look around for what some of that code would do.. but if you understand the code, and not the concept let me know and i can explain more...


Abydos
Link to comment
Share on other sites

Thank you Abydos for detailed reply, I dont have much Php experience but I am starting to understand the concept, just having trouble to fully understand the code and on how to implement it? :-\

I am using an example something very similar to what u suggested, i have two external language files(language1, language2) and the code below in the main page. It prety much does what I want to do just i have to click on the links(english, dutch) 2 times at least before any action takes place.

[quote]<?php
if (isset($_GET['lang'])) {
    $lang = $_GET['lang'];
    setcookie("language", "$lang", time()+36000);
    }
?>
<html>

<head>
  <title></title>
</head>

<body>

<?php

if (isset($_COOKIE['language'])) {
    $lang = $_COOKIE['language'];
    } else {
        $lang = english;
        }

switch ($lang) {
    case "english":
    require_once('english.php');
    break;
    case "dutch":
    require_once('dutch.php');
    break;
    default:
    case "english":
    require_once('english.php');
    break;
    }
echo "Please choose a language : <a href=?lang=english>English</a> || <a href=?lang=dutch>Dutch</a><br>";
echo (Welcome_Note);

echo (button);

?>

</body>

</html>[/quote]
Any idea why that is, or do you have a better, neat way of  implementing it, any thoughts will be much appriciated.thank you.

brusq
Link to comment
Share on other sites

[quote author=AbydosGater link=topic=115196.msg469557#msg469557 date=1163774573]
i dont know, it should work fine with one click, once the get is set...
what is the link to where your using the code..?
What are button and welcome_note?
Are they defined?
[/quote]

As I said they are defined(welcome , button) in two different language files. I am just looking to improve it, Also a might be a very basic question how do we use .tpl files to display php files. thank you for your help..

u can see a working example at  www.forumbahane.com/uniphp/indexlang.php
Link to comment
Share on other sites

Many stand alone apps have what they call a resource file. In this (amongst other things) is like a table of strings - one column for each language.

Now you could replecate this with a database table. So you would only ever have to translate the strings you actually use on your site - they all have their own unique id and hence you can simply switch language by switching which field in teh database to search on. The other side to this is geoip project (just google geoip or maxmind) where you can actually detect (reasonably accurately) which country your visitor is from and use that in you queries!

Always remeber to put a link somewhere to change the language if they need to though!
Link to comment
Share on other sites

easiest way i've found is to drop this to the top of your file
[code]
if(isset($_COOKIE[lang])) require_once('lang/'.$_COOKIE[lang].'.php');
else require_once('lang/english.php');
[/code]

then in your english.php
[code]
define("HOME","Home");
[/code]
or dutch.php
[code]
define("HOME","Huiswaarts");
[/code]
etc.

then in your code, you simply just
[code]
<a href="home.php"><?=HOME?></a>
[/code]
or whatnot... then all you have to do is set the cookie to change languages...
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.