Haunted Dawg Posted August 27, 2009 Share Posted August 27, 2009 Well, i just wanted to check if this is do able. And it pretty much is.. If you really wanted to expand your website. Here's a small method.. We use the $_SERVER['HTTP_ACCEPT_LANGUAGE'] php variable here. What we do is we mainly generate our file's in english. We then put all the word's we would like to translate in a huge array along with the english array. And here is a small snippet: <?php $foul = $_SERVER['HTTP_ACCEPT_LANGUAGE']; $sub = substr($foul, 0, 2); $languages = array( 'es' => 'Spanish', 'en' => 'English', ); if(!isset($_GET['lang'])) { ob_start($languages[$sub]); } function Spanish($all) { $spanish = array('hola','como','haces'); $english = array('hello','how','do'); return str_ireplace($english, $spanish, $all); } function English($all) { //Since our content is written in english, we dont need to replace anything } That for me would change, hello, how & do to the according spanish word's as my pc is spanish. I hope atleast some one find's this usefull. Quote Link to comment Share on other sites More sharing options...
Karlos94 Posted December 18, 2009 Share Posted December 18, 2009 You missed a key point.. For example: I Agree - English Acepto - Spanish Ich bin einverstanden - German Je suis d'accord - French All the same phrase, just translated.. So technically your function has a limit on what you can do... Why not keep it simple? Have a file of translations and link them into your actualy file.. I'm using CodeIgniter for a project I am doing, thought it'll be different from what I am use to, but anyway... Here is a snippet I use with CodeIgniter.. class Login extends Controller { private function getLang() { $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); if (!in_array($lang, array('en', 'es', 'de', 'fr'))) { $lang = 'en'; } //$lang = 'fr'; <-- Testing purposes only.. return $lang; } public function index() { // Blah blah... $this->lang->load('login', $this->getLang()); // Get information needed and pass it to the view. } } Quote Link to comment Share on other sites More sharing options...
sniko Posted December 18, 2009 Share Posted December 18, 2009 wow, cool, nice jobe well done Quote Link to comment Share on other sites More sharing options...
a_bertrand Posted December 18, 2009 Share Posted December 18, 2009 I would suggest you guys to check the ZapEngine (free / GNU) which contains a function called t() which allows you to handle localization of your game. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.