多语言PHP站点中的CSS图像替换问题

多语言PHP站点中的CSS图像替换问题,php,css,multilingual,image-replacement,Php,Css,Multilingual,Image Replacement,我正在用PHP和CSS构建一个多语言西班牙语/英语网站 我在common.php文件中有这段代码,根据用户定义的语言指向不同的css文件: <?php if ($_GET['lang'] == 'en') $cssFile = 'english.css'; elseif ($_GET['lang'] == 'es') $cssFile = 'espanol.css'; ?> 我的espanol.css文件如下所示: #rightHome h3 { padding-top: 20px

我正在用PHP和CSS构建一个多语言西班牙语/英语网站

我在common.php文件中有这段代码,根据用户定义的语言指向不同的css文件:

<?php
if ($_GET['lang'] == 'en')
$cssFile = 'english.css';
elseif ($_GET['lang'] == 'es')
$cssFile = 'espanol.css';
?>
我的espanol.css文件如下所示:

#rightHome h3 {
padding-top: 20px;
text-indent: -999px;
background: url(images/latestworkTitleES.png) no-repeat;
background-position: 0 20px;
}
<?php
include_once 'common.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Jimena Contreras | Film Scoring Composer</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="alternate" type="application/rss+xml" title="Jimena Contreras's News Feed"  href="http://www.jimenacontreras.com/news.xml" />
<link rel='index' title='Jimena Contreras | Film Scoring Composer' href='http://www.jimenacontreras.com/' />
<link rel='prev' title='Biography' href='http://www.jimenacontreras.com/biography' />
<link rel='next' title='Resume' href='http://www.jimenacontreras.com/resume' />
<link rel="shortcut icon" href="favicon.ico">
<meta name="description" content="Jimena Contreras is a film scoring composer based in  Mexico City specialized in feature films, short films, documentaries, spots & TV Series." />
<meta name="keywords" content="film scoring, composer, compositora, bandas sonoras, feature films, short film, TV Series, peliculas" />
<meta name="robots" content="INDEX, FOLLOW" />
<link href="styles.css" rel="stylesheet" />
<link href="menuprueba.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="<?php echo $cssFile; ?>" />
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/videobox.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript" src="js/contact-form.js"></script>
<script type="text/javascript" src="js/mootools.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/videobox.js"></script>
</head>
<body>
<div id="container">
<?php 
include ("header.php");
// Define our array of allowed $_GET values
$pass = array('home', 'biography', 'resume', 'filmography', 'contact', 'compositions- performed-or-broadcasted', 'resume2', 'resume3', '1015', 'i-laugh-not-to-cry', 'with-2-of-sugar', 'feminine-lips', 'crumbs-of-venus', 'pito-the-movie', 'the-mapuche-nation', 'creando-conciencia', 'building-unam', 'monsivais-honoris-causa', 'mexico-68-olympic-games', 'the-mexican-people', 'raining-colors', 'eyes-of-paradise');
// If the page is allowed, include it:
if (in_array($_GET['id'], $pass)) {
include ( $_GET['id'] . '.php'); 
}
// If there is no $_GET['id'] defined, then serve the homepage:
elseif (!isset($_GET['id'])) {
include ('home.php'); 
}   
?>
<?php 
include ("footer.php");
?>
</div>


</body>
</html>
<?php
/* 
------------------
Language: English
------------------
*/

$lang = array();

define('HEADING_NEWS', 'Latest News');
define('TEXT_NEWS1', '<span class="date">04.24.2011 </span>| <span class="news">Festival   Tour <br /><br /></span>Wishing the best of lucks for my last work "Crumbs from Venus",   shortfilm of Maira Bautista Neumann being sent to various festivals around the world.<br /><br />Good luck!');
define('TEXT_NEWS2', '<span class="date">02.26.2011 </span>| <span class="news">NYU! <br /><br /></span>Ready to start the adventure in NY in the ASCAP Workshop at NYU, will be taught by Sean Callery (24, La Femme Nikita).');
define('TEXT_NEWS3', '<span class="date">02.26.2011 </span>| <span class="news">New Project <br /><br /></span>Working on the soundtrack of P.I.T.O The Movie, a film by Fer Ortega, production by Yenin Escotto<br /><br />Click<a href="http://www.elpitolapelicula.com" target="_blank"> here </a> to go to the official website.');
?>
此外,我的索引如下所示:

#rightHome h3 {
padding-top: 20px;
text-indent: -999px;
background: url(images/latestworkTitleES.png) no-repeat;
background-position: 0 20px;
}
<?php
include_once 'common.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Jimena Contreras | Film Scoring Composer</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="alternate" type="application/rss+xml" title="Jimena Contreras's News Feed"  href="http://www.jimenacontreras.com/news.xml" />
<link rel='index' title='Jimena Contreras | Film Scoring Composer' href='http://www.jimenacontreras.com/' />
<link rel='prev' title='Biography' href='http://www.jimenacontreras.com/biography' />
<link rel='next' title='Resume' href='http://www.jimenacontreras.com/resume' />
<link rel="shortcut icon" href="favicon.ico">
<meta name="description" content="Jimena Contreras is a film scoring composer based in  Mexico City specialized in feature films, short films, documentaries, spots & TV Series." />
<meta name="keywords" content="film scoring, composer, compositora, bandas sonoras, feature films, short film, TV Series, peliculas" />
<meta name="robots" content="INDEX, FOLLOW" />
<link href="styles.css" rel="stylesheet" />
<link href="menuprueba.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="<?php echo $cssFile; ?>" />
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/videobox.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript" src="js/contact-form.js"></script>
<script type="text/javascript" src="js/mootools.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/videobox.js"></script>
</head>
<body>
<div id="container">
<?php 
include ("header.php");
// Define our array of allowed $_GET values
$pass = array('home', 'biography', 'resume', 'filmography', 'contact', 'compositions- performed-or-broadcasted', 'resume2', 'resume3', '1015', 'i-laugh-not-to-cry', 'with-2-of-sugar', 'feminine-lips', 'crumbs-of-venus', 'pito-the-movie', 'the-mapuche-nation', 'creando-conciencia', 'building-unam', 'monsivais-honoris-causa', 'mexico-68-olympic-games', 'the-mexican-people', 'raining-colors', 'eyes-of-paradise');
// If the page is allowed, include it:
if (in_array($_GET['id'], $pass)) {
include ( $_GET['id'] . '.php'); 
}
// If there is no $_GET['id'] defined, then serve the homepage:
elseif (!isset($_GET['id'])) {
include ('home.php'); 
}   
?>
<?php 
include ("footer.php");
?>
</div>


</body>
</html>
<?php
/* 
------------------
Language: English
------------------
*/

$lang = array();

define('HEADING_NEWS', 'Latest News');
define('TEXT_NEWS1', '<span class="date">04.24.2011 </span>| <span class="news">Festival   Tour <br /><br /></span>Wishing the best of lucks for my last work "Crumbs from Venus",   shortfilm of Maira Bautista Neumann being sent to various festivals around the world.<br /><br />Good luck!');
define('TEXT_NEWS2', '<span class="date">02.26.2011 </span>| <span class="news">NYU! <br /><br /></span>Ready to start the adventure in NY in the ASCAP Workshop at NYU, will be taught by Sean Callery (24, La Femme Nikita).');
define('TEXT_NEWS3', '<span class="date">02.26.2011 </span>| <span class="news">New Project <br /><br /></span>Working on the soundtrack of P.I.T.O The Movie, a film by Fer Ortega, production by Yenin Escotto<br /><br />Click<a href="http://www.elpitolapelicula.com" target="_blank"> here </a> to go to the official website.');
?>
我的lang.en.php文件如下所示:

#rightHome h3 {
padding-top: 20px;
text-indent: -999px;
background: url(images/latestworkTitleES.png) no-repeat;
background-position: 0 20px;
}
<?php
include_once 'common.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Jimena Contreras | Film Scoring Composer</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="alternate" type="application/rss+xml" title="Jimena Contreras's News Feed"  href="http://www.jimenacontreras.com/news.xml" />
<link rel='index' title='Jimena Contreras | Film Scoring Composer' href='http://www.jimenacontreras.com/' />
<link rel='prev' title='Biography' href='http://www.jimenacontreras.com/biography' />
<link rel='next' title='Resume' href='http://www.jimenacontreras.com/resume' />
<link rel="shortcut icon" href="favicon.ico">
<meta name="description" content="Jimena Contreras is a film scoring composer based in  Mexico City specialized in feature films, short films, documentaries, spots & TV Series." />
<meta name="keywords" content="film scoring, composer, compositora, bandas sonoras, feature films, short film, TV Series, peliculas" />
<meta name="robots" content="INDEX, FOLLOW" />
<link href="styles.css" rel="stylesheet" />
<link href="menuprueba.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="<?php echo $cssFile; ?>" />
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/videobox.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript" src="js/contact-form.js"></script>
<script type="text/javascript" src="js/mootools.js"></script>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/videobox.js"></script>
</head>
<body>
<div id="container">
<?php 
include ("header.php");
// Define our array of allowed $_GET values
$pass = array('home', 'biography', 'resume', 'filmography', 'contact', 'compositions- performed-or-broadcasted', 'resume2', 'resume3', '1015', 'i-laugh-not-to-cry', 'with-2-of-sugar', 'feminine-lips', 'crumbs-of-venus', 'pito-the-movie', 'the-mapuche-nation', 'creando-conciencia', 'building-unam', 'monsivais-honoris-causa', 'mexico-68-olympic-games', 'the-mexican-people', 'raining-colors', 'eyes-of-paradise');
// If the page is allowed, include it:
if (in_array($_GET['id'], $pass)) {
include ( $_GET['id'] . '.php'); 
}
// If there is no $_GET['id'] defined, then serve the homepage:
elseif (!isset($_GET['id'])) {
include ('home.php'); 
}   
?>
<?php 
include ("footer.php");
?>
</div>


</body>
</html>
<?php
/* 
------------------
Language: English
------------------
*/

$lang = array();

define('HEADING_NEWS', 'Latest News');
define('TEXT_NEWS1', '<span class="date">04.24.2011 </span>| <span class="news">Festival   Tour <br /><br /></span>Wishing the best of lucks for my last work "Crumbs from Venus",   shortfilm of Maira Bautista Neumann being sent to various festivals around the world.<br /><br />Good luck!');
define('TEXT_NEWS2', '<span class="date">02.26.2011 </span>| <span class="news">NYU! <br /><br /></span>Ready to start the adventure in NY in the ASCAP Workshop at NYU, will be taught by Sean Callery (24, La Femme Nikita).');
define('TEXT_NEWS3', '<span class="date">02.26.2011 </span>| <span class="news">New Project <br /><br /></span>Working on the soundtrack of P.I.T.O The Movie, a film by Fer Ortega, production by Yenin Escotto<br /><br />Click<a href="http://www.elpitolapelicula.com" target="_blank"> here </a> to go to the official website.');
?>
现在的问题是,在我的主页上,当你在英语和西班牙语之间切换时,一切正常,这意味着文本和图像会发生变化,但当你点击进入另一个页面(如传记)时,文本会被翻译,但图像保持不变,所以我的问题是,我做错了什么

要查看站点工作,您可以转到

非常感谢您的帮助,我希望我足够清楚,并且我的问题很容易理解

提前谢谢


J.C.查韦斯S.

除标题部分外,任何页面上都没有“?lang=es”或“?lang=en”部分。 因此什么也得不到。 我个人建议使用不同语言的文件夹结构,而不是尝试使用相同的url。 比如:而不是你在做什么。 您可以在db中存储英语和西班牙语文本,并在include configs文件中设置语言。每个语言文件夹将有一个单独的配置文件

如果您想坚持这样做,您可以为cssFile设置一个会话变量,并在每个页面顶部检查它。 有件事是这样的:

<?php
  if (isset($_GET['lang'])){
     if ($_GET['lang'] == 'en'){
      $cssFile = 'english.css';
  }
      elseif ($_GET['lang'] == 'es'){
  $cssFile = 'espanol.css';
  }
      $_SESSION['lang '] = $cssFile;
  }elseif(isset($_SESSION['lang'])){
   $cssFile =  $_SESSION['lang '];
  }
   ?>
在速度方面,拥有一堆不同的css和javascript文件也是一个可怕的想法。

在body标记中添加lang属性,或者在它应用的地方,有很多HTML标记都有lang属性

在CSS中,您可以创建只匹配特定语言的选择器,以便选择正确的背景图像。这是通过以下步骤完成的

通过这种方式,您可以将数据、语言信息与样式图形分离

body[lang=en] #header { your engish graphic } 
body[lang=es] #header { your spanish graphic }
根据对CSS版本的支持,还有


Ref:

我不确定我应该看到什么问题。当我进入传记页面时,我会在哪里看到问题,它会是什么样子?我在传记页面上也没有看到任何h3标签,所以我不确定是否还有其他你没有提到的图像替换案例。顺便说一句,你的网站看起来不错,虽然速度很慢。嘿,谢谢你回复得这么快,当你用英语进入传记页面时,页面右侧文字上方的标题是传记,如果你选择西班牙语,应该是传记,但它只会用英语。此外,在bio页面中只有h2标签,但图像替换与主页中的h3标签完全相同。谢谢,我很高兴你喜欢它,你会推荐什么来加速它呢?有几件事可以帮助网站性能:组合css文件-浏览器检索文件所需的http请求越少,网站通常会越快。脚本也是如此。在正文底部加载脚本,这样当页面尝试加载或使用类似Load.js的内容时,脚本就不会阻止DOM构造。请确保您正在尽可能使用css精灵,以及尽可能使用最有效的图像格式。酷哥,感谢您提供的有关网站性能的建议,我会尝试应用它们,看看效果如何。我忘了在产品中包含太多-缩小css和javascript-这会减少文件大小,如果您开始组合它们,这将非常有用。您好,在我的标题中有“?lang=es”和“lang=en”,我认为把它放在那里,并在我的索引文件中包含我的头文件,就足以让它工作了。另外,我对数据库也不是很熟悉,所以任何我能阅读的文档都将不胜感激。如果我想坚持下去,我必须把你给我的代码放在每一页上?例如,bio页面看起来是这样的:

从url地址获取读取信息,而您仅在一个页面上获取此信息-如果您实际单击英语/西班牙语。当你转到另一个页面时,它没有。如果你不想为不同的语言创建一个单独的文件夹,那么就使用sessions。好吧,我刚把这段代码放在我的bio页面上,但什么都没发生,你会建议把所有的javascript文件放在一个文件夹中,以加快速度吗?顺便说一句,非常感谢您花时间来帮助我:您必须在任何其他代码之前打开会话。如果您使用的是可能应该包含的头文件,请在那里执行。否则在每个文件的顶部。会议开始;请阅读此处:。是的,将js文件合并成一个或两个会加快速度。css也是如此。你将从你的页面上进行更少的HTTP调用。谢谢你的回答,我会检查这个,因为这对我来说是全新的,所以我真的不知道如何在网站上实现它