Earlier, I used a drop-down list with options that use the post method to change the language on the web page, which is saved in a separate file. Now I'm trying to create something similar, but I need help. Now I'm trying to make a web page in only 2 languages, and when viewing a web page in one language, it will be possible to switch to another. Essentially giving the viewer the opportunity to change the session language into English or Spanish only with the display of the opposite language as a hyperlink on all pages. My language file essentially looks like this:
<?php
$lang = array(
'EN' => array(
'ABOUT' => 'About',
'HOME' => 'Home'
),
'SP' => array(
'ABOUT' => 'Acerca',
'HOME' => 'Casa'
)
)
?>
PHP-, , , , , . html-, :
<?php
require("lang.php");
session_start();
$_SESSION['LANG'] = "EN";
if(@$_POST['lang-chooser']){
$_SESSION['LANG'] = $_POST['lang-chooser'];
}
?>
, , . , , :
<form method="post" action="" id="lang-form">
<select id="lang-chooser" class="lang-chooser" name="lang-chooser" onchange="window.lang(this);">
<option value="EN"<?php if($_SESSION['LANG'] == "EN") {?> selected="selected"<?php }?>>English</option>
<option value="SP"<?php if($_SESSION['LANG'] == "SP") {?> selected="selected"<?php }?>>Spanish</option>
</select>
</form>
, , script :
<script type="text/javascript">
function lang(element){
var lang_name = element.value;
var e_form = document.getElementById("lang-form");
e_form.submit();
console.log(element);
}
window.lang = lang;
</script>
, , . , , :
<?php echo ($lang[$_SESSION['LANG']]['ABOUT']); ?>
, . , , , , , Espanol, , , , , . , PHP- javascript, "" "", . , , , "form" "posting-method" :
<a href="index.php?LANG=SP"> <?php echo($lang[$_SESSION['LANG']]['SPANISH']); ?> </a>
, , . , , . , . , , .