更改链接点击语言 [英] Change language on link click

查看:91
本文介绍了更改链接点击语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接,例如:

 < a href =index.php ?lang = en>< img src =images / uk.pngstyle =height:20px/>< / a> 



在index.php中的页面:

 <?php 
session_start();
header('Cache-control:private'); // IE 6 FIX

if(isSet($ _ GET ['lang']))
{
$ lang = $ _GET ['lang'];

//注册会话并设置cookie
$ _SESSION ['lang'] = $ lang;

setcookie(lang,$ lang,time()+(3600 * 24 * 30));
}
else if(isSet($ _ SESSION ['lang']))
{
$ lang = $ _SESSION ['lang'];
}
else if(isSet($ _ COOKIE ['lang']))
{
$ lang = $ _COOKIE ['lang'];
}
else
{
$ lang ='en';
}

switch($ lang){
case'en':
$ lang_file ='lang.en.php';
休息;

格'gr':
$ lang_file ='lang.gr.php';
休息;

默认值:
$ lang_file ='lang.en.php';

}

include_once'languages /'.$ lang_file;
?>

它将URL更改为 index.php?lang = gr 读取参数 LANG 并翻译页面取决于此参数。



如何更改我的代码来做到这一点,而不需要将参数传递给Url?我的意思是,我希望用户留在同一页面上,并在页面刷新时更改语言。

如下所示;

 < input type =submitvalue =class =<?php if($ _SESSION ['lang'] ==tr){echosubmittr; } else {echosubmiten;}?>> 

在这种情况下,您将被更改类的类型

I have a links such as:

<a href="index.php?lang=en"><img src="images/uk.png" style="height:20px"/></a>

And and included page in index.php:

<?php
session_start();
header('Cache-control: private'); // IE 6 FIX

if(isSet($_GET['lang']))
{
$lang = $_GET['lang'];

// register the session and set the cookie
$_SESSION['lang'] = $lang;

setcookie("lang", $lang, time() + (3600 * 24 * 30));
}
else if(isSet($_SESSION['lang']))
{
$lang = $_SESSION['lang'];
}
else if(isSet($_COOKIE['lang']))
{
$lang = $_COOKIE['lang'];
}
else
{
$lang = 'en';
}

switch ($lang) {
  case 'en':
  $lang_file = 'lang.en.php';
  break;

  case 'gr':
  $lang_file = 'lang.gr.php';
  break;

  default:
  $lang_file = 'lang.en.php';

}

include_once 'languages/'.$lang_file;
?>

It changes the URL to index.php?lang=gr reads the parameter LANG and translates the page depends on this parameter.

How can I change my code to do it without passing the parameter to Url? What I mean is, that I want a user to stay on the same page and change the language on page refresh.

解决方案

It would be as below ;

        <input type="submit" value="" class=<?php if( $_SESSION['lang']  == "tr" ) { echo "submittr";  } else { echo "submiten";} ?>>

In that case you will be changed type of the class

这篇关于更改链接点击语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆