1

我正在使用 PHP 和 CSS 构建多语言(西班牙语/英语)网站。

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

<?php
if ($_GET['lang'] == 'en')
$cssFile = 'english.css';
elseif ($_GET['lang'] == 'es')
$cssFile = 'espanol.css';
?>

这是我的 english.css 文件的外观示例:

#rightHome h3 {
padding-top: 20px;
text-indent: -999px;
background: url(images/latestworkTitle.png) no-repeat;
background-position: 0 20px;
}

我的 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>

我的 lang.en.php 文件如下所示:

<?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.');
?>

现在的问题是,在我的主页中,当您在英语和西班牙语之间切换时,一切正常(意味着文本和图像发生变化),但是当您单击转到另一个页面(例如传记)时,文本被翻译但图像保持不变,所以我的问题是,我做错了什么?

要查看该网站的工作情况,您可以访问http://www.jimenacontreras.com

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

提前致谢。

JC 查韦斯 S.

4

2 回答 2

0

为 body 标签添加一个lang属性(或者它适用的地方),这是一个非常通用的属性,所以很多 HTML 标签都有它。

然后,在 CSS 中,您可以创建仅匹配特定语言的选择器,例如选择正确的背景图像。这是通过属性选择器完成的完成的。

通过这种方式,您可以将数据(语言信息)与样式(图形)分开。

body[lang=en] #header { your engish graphic } 
body[lang=es] #header { your spanish graphic }

根据 CSS 版本的支持,还有CSS 2.1 :lang 伪类

参考:设计双语网站:快速案例研究

于 2011-06-14T00:12:25.537 回答
0

除了标题一之外,您在任何页面上都没有 '?lang=es' 或 '?lang=en' 部分。因此 GET 什么也不返回。我个人会建议对不同语言使用文件夹结构,而不是尝试使用相同的 url。喜欢:http ://www.jimenacontreras.com/和http://www.jimenacontreras.com//es而不是你在做什么。您可以将英语和西班牙语文本存储在数据库中,并在包含配置文件中进行语言设置(每个语言文件夹都有一个单独的配置文件。

如果你想坚持这一点,你可以为 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 文件在速度方面是一个可怕的想法。

于 2011-06-13T23:36:02.507 回答