ziedinjsh Posted October 21, 2009 Report Share Posted October 21, 2009 Pats valodas slēdzis strādā, bet nevaru izdomāt kā novērst šādu problēmu.. lapas menu linki ir šādi: echo "<div id='menu-link' onclick=\"location.href='".$url."';\" alt='".$lang['2']."' >".$lang['2']."</div>"; echo "<div id='menu-link' onclick=\"location.href='".$url."?show=cenas';\" alt='".$lang['3']."'>".$lang['3']."</div>"; echo "<div id='menu-link' onclick=\"location.href='".$url."?show=kontakti';\" alt='".$lang['4']."'>".$lang['4']."</div>"; un valodas slēdzim ir tādi paši var teikt: echo "<div id='lang-link' onclick=\"location.href='?lang=lv';\" alt='Latviešu valoda'>LV</div>"; echo "<div id='lang-link' onclick=\"location.href='?lang=ru';\" alt='Pусский язык'>RU</div>"; Jūs jau saprotat kas notiek.. uzpiežou uz ru valodu un uzpiežot uz kādu linku no izvēlnes uzreiz ir latviešu valodā.. Valodas slēdzis: $languages = array( 'lv' => 'lv', 'ru' => 'ru', ); if (isset($_GET['lang']) AND array_key_exists($_GET['lang'], $languages)) { include 'lang/' . $languages[$_GET['lang']] . '.php'; } else { include 'lang/lv.php'; } vai var kāds palīdzēt novērst šādu problēmu.. Izvēloties valodas es brīvi var slēgāt menu un būtu izvēlētajā valoda Paldies jau iepriekš! :) Quote Link to comment Share on other sites More sharing options...
indoom Posted October 21, 2009 Report Share Posted October 21, 2009 Saglabā sesijā izvēlēto valodu Quote Link to comment Share on other sites More sharing options...
waplet Posted October 21, 2009 Report Share Posted October 21, 2009 saglabā kūkijā vai sesija. 2.ja ir iesettota sesija pārbaudi, ja ir valoda kāda liec to valodu, citādāk taisi switchu Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 21, 2009 Author Report Share Posted October 21, 2009 (edited) tas ir kaut kā šādi? $languages = array('lv' => 'lv', 'ru' => 'ru'); if (!isset($_SESSION['lang']) AND array_key_exists($_SESSION['lang'], $languages)) { include 'lang/' . $languages[$_SESSION['lang']] . '.php'; } else { include 'lang/lv.php'; } Edited October 21, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
indoom Posted October 21, 2009 Report Share Posted October 21, 2009 if (isset($_SESSION['lang']) && ... Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 21, 2009 Author Report Share Posted October 21, 2009 nesapratu :? Quote Link to comment Share on other sites More sharing options...
indoom Posted October 21, 2009 Report Share Posted October 21, 2009 (edited) tev ir if (!isset($_SESSION['lang']), bet vajag bez ! pirms isset(). if (isset($_SESSION['lang']) && array_key_exists($_SESSION['lang'], $languages)) { } Bez tam tajā $languages arrayā nav ērtāk rakstīt $languages = array('lv','ru');? Un tad array_key_exists vietā izmantot in_array($_SESSION['lang'],$languages). Attiecīgi include 'lang/' . $_SESSION['lang'] . '.php'; Edited October 21, 2009 by indoom Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 21, 2009 Author Report Share Posted October 21, 2009 (edited) lab tad tagad viņam ir jāizskatās šadi: $languages = array('lv','ru'); if (isset($_SESSION['lang']) && in_array($_SESSION['lang'], $languages)) { include 'lang/' . $languages[$_SESSION['lang']] . '.php'; } else { include 'lang/lv.php'; } bet tad kāds tagad sanāk links? tāds pats kā bija echo "<div id='lang-link' onclick=\"location.href='".$url."?lang=lv';\" alt='Latviešu valoda'>LV</div>"; echo "<div id='lang-link' onclick=\"location.href='".$url."?lang=ru';\" alt='Pусский язык'>RU</div>"; vai arī savādāks? Edited October 21, 2009 by ziedinjsh Quote Link to comment Share on other sites More sharing options...
indoom Posted October 21, 2009 Report Share Posted October 21, 2009 (edited) Paskaties vērīgāk iepriekšejo postu include 'lang/' . $_SESSION['lang'] . '.php'; tiem linkiem izmanto to ko sākumā ar $_GET darīji, vajadzīgajā vietā saglabājot $_SESSION['lang'] = $_GET['lang'] pēc GET pārbaudes pārbaudes. Protams, tur includes vairs nav vajadzīgas. Šis pēdējais bija tikai, lai klikšķinot pa menju, saglabājas izvēlētā valoda. $languages = array('lv','ru'); if (isset($_GET['lang']) && in_array($_GET['lang'],$languages)) { $_SESSION['lang'] = $_GET['lang']; } if (isset($_SESSION['lang']) && in_array($_SESSION['lang'], $languages)) { include 'lang/' . $_SESSION['lang'] . '.php'; } else { include 'lang/lv.php'; } Edited October 21, 2009 by indoom Quote Link to comment Share on other sites More sharing options...
ziedinjsh Posted October 21, 2009 Author Report Share Posted October 21, 2009 ak šitā.. es nevarēju saprast pēc tā tava pēdējā teikuma paldies par palīdzību indoom :) Quote Link to comment Share on other sites More sharing options...
Kavacky Posted October 21, 2009 Report Share Posted October 21, 2009 Glabāt sesijā nav stilīgi, vajag valodas parametru padot līdzi visos linkos. Un valodas switchā vajag valodas parametriem dot līdzi visos šābrīža parametrus, lai nelec uz sākumlapu. Quote Link to comment Share on other sites More sharing options...
ohmygod Posted October 21, 2009 Report Share Posted October 21, 2009 Kavacky - sesijā glabāt valodu IR stilīgi. Protams, to ir jāpadod arī linkā, bet ja nu linkā nav, tad būtu jāizmanto sesijā atrodamā. Un dot līdzi parametrus var tikai tad, ja dažādu valodu kontenti ir vienādi. Ļoooti bieži tā nav un ko tad? Padot līdzi nederīgus parametrus? Quote Link to comment Share on other sites More sharing options...
Kavacky Posted October 22, 2009 Report Share Posted October 22, 2009 [..] ja dažādu valodu kontenti ir vienādi. Ļoooti bieži tā nav [..] Tas arī nav stilīgi. XD 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.