Quote:
Originally Posted by Clean_Franck
Hey for the moment I would like to just get automatic setup. Once I have some spare cash then I can go down the proper route. But just need to know how to go about it.
|
ok heres what this does
It grabs an glob of text like a welcome message from a txt file
en.txt for english
fr.txt for french
etc etc
if you dont have a txt file for that language it displays a link to translate the page in place of where the message would be ( KEEP IN MIND THE WORDS "TRANSLATE THIS PAGE" ARE IN ENGLISH )
Code:
<?php
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$pageURL = urlencode($pageURL);
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$lang = strtolower($lang);
$file="$lang.txt";
if (file_exists($file)) {
$message = file_get_contents("$file");
} else {
$message = "<a href=\"http://babelfish.yahoo.com/translate_url?doit=done&tt=url&intl=1&fr=bf-home&trurl=$pageURL&lp=en_$lang&btnTrUrl=Translate\">TRANSLATE THIS PAGE</a>";
}
echo $message;
?>
using this method you could add a txt file message for each language as you add them without altering those code.
the drawback is they must be able to read the words "translate this page" in english to understand they can translate the page.
------------------------------------------------
below is some diff code , this will automatically redirect the user to the babelfish translator if you dont have a message .txt for that language
Code:
<?php
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
$pageURL = urlencode($pageURL);
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$lang = strtolower($lang);
$file="$lang.txt";
if (file_exists($file)) {
$message = file_get_contents("$file");
} else {
$message = "<script>top.location.href = \"http://babelfish.yahoo.com/translate_url?doit=done&tt=url&intl=1&fr=bf-home&trurl=$pageURL&lp=en_$lang&btnTrUrl=Translate\";</script>";
}
echo $message;
?>
p.s. i havent tested either of these out, if you have a problem just let me know.
so for example on gfy where it says "where the industry meets" if you put this code right where it says that then made a txt file called en.txt for english and put "where the industry meets" then made a few more with proper translation for popular languages , if someone visited this page they would see the messagein their language, unless gfy didnt have their particular language translated then it would send them to the babelfish translator
below is an example of the babelfish page translator.. translating gfy.com to french
http://babelfish.yahoo.com/translate...rUrl=Translate