Witam,
Ostatnio przerobiłem wielojęzyczność na stronie i działa poprawnie. W związku z tym proszę o ocenę na ile jest ona poprawna od strony technicznej.
Przełączanie menu np w pliku banner.inc.php
<form action="" method="post"> <input class="flaga_pl" type="submit" name="lang" value="pl" /> <input class="flaga_en" type="submit" name="lang" value="en" /> <input class="flaga_es" type="submit" name="lang" value="es" />
plik index.php
<?
ini_set( 'arg_separator.output', '&' );
if ( !isset ($_SESSION['lang'])) {
if ( isset ($_POST['lang'])) {
$_SESSION['lang'] = $_POST['lang'];
}
else
{
$_SESSION['lang']= pl;
}
}
include('head.' . $_SESSION[lang] . '.inc.php');
include( './lang/'.$_SESSION[lang].'/menu.txt.php');
include( './lang/'.$_SESSION[lang].'/text.txt.php');
?>
<div id="container">
<div id="banner"><? include("include/banner.inc.php");?></div>
<div id="window"><? include("include/window.inc.php");?></div>
<div id="footer"><? include("include/footer.inc.php");?></div>
</div>
</body>
</html>
plik include/head.$_SESSION[lang].inc.php
w zależności od języka zmieniamy ustawienia nagłówka (temat, zawrtość, itd)
<? echo '<?xml version="1.0" encoding="UTF-8"?>' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta name="author" content="abc" />
<meta name="description" content="abc" />
<title>:: abc ::</title>
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="css/ie7.css" /><![endif]-->
<link rel="stylesheet" type="text/css" href="css/common.css" />
<link rel="stylesheet" type="text/css" href="css/layout_1.css" title="Podstawowy" />
</head>
<body>
w pliku css
input.flaga_es {
background-image: url(../img/flagi/flaga_es.gif);
background-repeat: no-repeat;
width: 24px;
height: 18px;
background-color: transparent;
float: left;
font-size: 0;
}
input.flaga_en {
background-image: url(../img/flagi/flaga_en.gif);
background-repeat: no-repeat;
width: 24px;
height: 18px;
background-color: transparent;
float: left;
font-size: 0;
}
input.flaga_pl {
background-image: url(../img/flagi/flaga_pl.gif);
background-repeat: no-repeat;
width: 24px;
height: 18px;
background-color: transparent;
float: left;
font-size: 0;
}
w plikach języków
<?php
// ustawiam zmienną jako tablice
// opisy menu - linki:
$lng['tekst'] = 'tekst w odpowiednim języku';
?>
w treści strony wstawiam
<?
tu pojawi się ".$lng['tekst']."dla danej wersji językowej";
?>
Pozdrawiam i czekam na ocenę.
Piotr
Ten post edytował psbert 31.10.2008, 13:54:56