Some people have told me that the following code is bad for HTML validation:
index.php:
line 1 ~ 5 (this one is OK. Just for reference):
<?php include_once 'localization.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
line 15 (if Chinese is selected load those CSS files):
<?php if($lang_file=='lang.zh-tw.php' || $lang_file=='lang.zh-cn.php')
{echo '<link rel="stylesheet" type="text/css" href="styles/chinese.css" />';} ?>
line 21 (if English is the current language change assign to it the class: current):
<li <?php if($lang_file=='lang.en.php') {echo 'class="current"';} ?>>
<a href="index.php?lang=en">ENGLISH</a></li>
line 168 ~ 171 (this is the only way I found to add different languages to the jquery validation plugin):
<?php if($lang_file=='lang.en.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-en.js"></script>';} ?>
<?php if($lang_file=='lang.es.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-es.js"></script>';} ?>
<?php if($lang_file=='lang.zh-tw.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-zh-tw.js"></script>';} ?>
<?php if($lang_file=='lang.zh-cn.php') {echo '<script type="text/javascript" src="scripts/jquery-validate/val-zh-cn.js"></script>';} ?>
lozalization.php (for reference only):
<?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';
}
// use appropiate lang.xx.php file according to the value of the $lang
$languages = array('en', 'es', 'zh-tw', 'zh-cn');
if (in_array($_SESSION['lang'], $languages)) {
$lang_file = 'lang.'.$_SESSION['lang'].'.php';
} else {
$lang_file = 'lang.en.php';
}
//localization helper function
function l($localization) {
global $lang;
return $lang[$localization];
}
include_once 'languages/'.$lang_file;
?>
I am falling into bad practices or validation problems? The code works, but is there's a way of doing the things above in a cleaner and better way?