Amy1980 Posted November 29, 2006 Share Posted November 29, 2006 Hello Boys [and maybe Girls]!I have problem. I wanna to make my site multi language. I want to make it similar like PHP-Nuke is. I don't want to make it with URLs like[code]index.php?lang=de[/code]W would like to make it on cookies. Can You help me? I was trying for few days but I didn't make nothing right. Can You help me?Thanx in advance!!edit:I found something interesting[url=http://www.phpfreaks.com/forums/index.php/topic,112507.0.html]http://www.phpfreaks.com/forums/index.php/topic,112507.0.html[/url]but this user has wrote new topic that cookies doesn't work. Do You think is it good way? If yes, what to do with cookies? Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 29, 2006 Share Posted November 29, 2006 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 sayDEFINE("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 PS: I copyed this post from when i posted it in the topic at http://www.phpfreaks.com/forums/index.php/topic,115196.0.html Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted November 29, 2006 Author Share Posted November 29, 2006 Thanks for reply!!!!!But it works on URLs; I think. If not sorry, but I haven't use php for 2 years:)This looks good, but how to make other file to changes language, to not use URL's? Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 29, 2006 Share Posted November 29, 2006 There are many ways.. On the main page of your website have a dropdown box with languages.. and when the user selects one, and sends the form, process it and save the language they want in a session or cookie.. then just call the session or cookie to a variable and include that language file!Understand? if not i can explain more :D Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted November 29, 2006 Author Share Posted November 29, 2006 I decided to make it with pedro84's method. It seems good to me.Ok. I wanna to make cookie to this method but I couldn't:/This is itindex.php[code]<?phpsession_start();require_once("langman.php");if(!SelectLanguage ($_SESSION["lang"])) die ("Error");?>[/code]langman.php[code]<?php$language = array();function SelectLanguage($strLang){ global $language; $inc = "en"; switch(stripslashes($strLang)) { case "de": $inc = "de"; break; case "en": $inc = "en"; break; case "pl": $inc = "pl"; break; default: $inc = "en"; } include_once("languages/" . $inc . ".inc"); if(isset($lang)) { $language = $lang; return true; } return false;}?>[/code]setlang.php[code]<?phpsession_start();$strLang = $_GET["lang"];$_SESSION["lang"] = stripslashes($strLang);header("Location: index.php"); //** redirect to where u want...?>[/code]Setlang.php changes laguages but I have big problem with adding cookie to this file. Can Anyone help my?:> Hmm I think i must add cookie to setlang.php;) Quote Link to comment Share on other sites More sharing options...
pedro84 Posted November 29, 2006 Share Posted November 29, 2006 Ok. I have quasi done it.I need only something like that:If cookie exist, read language from it, if don't send it...hmm how to do that? Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 29, 2006 Share Posted November 29, 2006 if the cookies not set.. make the default to english and set the cookie as english... then you have a form somewhere on your site to change the value of the cookie Quote Link to comment Share on other sites More sharing options...
pedro84 Posted November 29, 2006 Share Posted November 29, 2006 Could You be so nice and show me how to do that? I have the same problem in other topic! Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 30, 2006 Share Posted November 30, 2006 I could show you how to do it with sessions, cause i dont use cookies :P[code]<?phpif (!$_SESSION['language']){$language = "english.php";} else {$language = $_SESSION['language'];}require("/languages/$language");?>[/code]Just make sure when you set the session (or cookie whatever way you do it) to include the .php; :P Quote Link to comment Share on other sites More sharing options...
taith Posted November 30, 2006 Share Posted November 30, 2006 [code]<?(isset($_COOKIE[Lang])) ? require_once('lang/'.$_COOKIE[Lang].'.php') : require_once('lang/english.php');?>[/code]then all ya gotta do is set that cookie "Lang" to any language it wants, and it will load that language file :-) Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted November 30, 2006 Author Share Posted November 30, 2006 [quote author=taith link=topic=116754.msg476191#msg476191 date=1164893772][code]<?(isset($_COOKIE[Lang])) ? require_once('lang/'.$_COOKIE[Lang].'.php') : require_once('lang/english.php');?>[/code]then all ya gotta do is set that cookie "Lang" to any language it wants, and it will load that language file :-)[/quote]Where to put it?:> :D Quote Link to comment Share on other sites More sharing options...
taith Posted November 30, 2006 Share Posted November 30, 2006 right at the very top :-P Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted November 30, 2006 Author Share Posted November 30, 2006 OF index.php or setlang.php?Damn, I feel like f*** noob :'(I have to do this, I promised my boyfriend that I make it for him:)Please, help ME! ;D Quote Link to comment Share on other sites More sharing options...
taith Posted November 30, 2006 Share Posted November 30, 2006 lol... top of the index.php Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted November 30, 2006 Author Share Posted November 30, 2006 LOLDamn, show me how should look index.php or I get frustrated ??? ??? Quote Link to comment Share on other sites More sharing options...
taith Posted November 30, 2006 Share Posted November 30, 2006 [code]<?#top of index.phpsession_start();(isset($_COOKIE[Lang])) ? require_once('lang/'.$_COOKIE[Lang].'.php') : require_once('lang/english.php');#restoffile...?>[/code] Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted November 30, 2006 Author Share Posted November 30, 2006 When I Put it I get "error selecting language. Damn ??? Quote Link to comment Share on other sites More sharing options...
Amy1980 Posted December 1, 2006 Author Share Posted December 1, 2006 Hmm. It could be, but I'm looking for something with sessions and cookies. I;m thinking all the free time of the isset, but I cannot write it correctly.I used something like that:[code]include ('news_ '.$_SESSION['lang'].'/index.php [/code]When users choose Polish lang, it includes news_pl/index.php.I wanna to make something like this:[code]include (news_ if exist $_COOKIE['lang'] /if don't $_SESSION['lang']/index.php[/code]You know what I mean?It must be simple. PHP-Nuke by F. Burzi works this way. 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.