I make a website in html without a template according to this scheme:

  • At the root of the site is index.html and two folders, en and ru , with the English and Russian versions of the site, respectively.

  • index.html , which is at the root, they have a common one and it has a built-in language switch code taken from the answer to the question “Language switch on JQ” . This code works great / I just plugged in the pictures of flags, instead of text links.

Here is the code index.html :

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>R2FBT amateur radio station</title> <meta name="keywords" content="amateur, radio, station" /> <meta name="description" content="Home page R2FBT" /> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="bg"> <div id="main"> <!-- header begins --> <div id="header"> <ul class="menu-main"> <li><a href="index.html" class="but_t" title="">HOME</a></li> <li><a href="biography.html" class="but" title="">BIOGRAPHY</a></li> <li><a href="eqipment.html" class="but" title="">EQIPMENT</a></li> <li><a href="qsl.html" class="but" title="">QSL</a></li> <li><a href="logbook.html" class="but" title="">LOGBOOK</a></li> <li><a href="dx_cluster.html" class="but" title="">DX CLUSTER</a></li> <li><a href="rbn_map.html" class="but" title="">RBN map</a></li> <li><a href="rbn_graph.html" class="but" title="">RBN on graph</a></li> <li><a href="products.html" class="but" title="">PRODUCTS</a></li> <li><a href="contacts.html" class="but" title="">CONTACTS</a></li> </ul> <script src="/r2fbt.ru/logbook/js/jquery-1.7.2.js" type="text/javascript"> </script> <ul class="language-select"> <li class="active" data-lang="en" style="background: url('images/en.png') no-repeat left center;"></li> <li data-lang="ru" style="background: url('images/ru.png') no-repeat left center;"></li> </ul> <script> $('.language-select').click(function(){ $(this).toggleClass('open'); }) $('.language-select li').click(function(){ var setLang = $('.language-select').data('location'), dataLangSelect = $(this).data('lang') $('.language-select').data('location', dataLangSelect); $('.language-select li').removeClass('active'); $(this).toggleClass('active'); }) </script> 

The question is how to connect this script to the site so that when choosing for example English in the menu, the path to the English pages is substituted:

 <li><a href="/r2fbt.ru/en/biography.html" class="but" title="">BIOGRAPHY</a></li> 

and when choosing the Russian language - to the Russian pages:

 <li><a href="/r2fbt.ru/ru/biography.html" class="but" title="">BIOGRAPHY</a></li> 
  • just like that. do on php, java, etc. - Tsyklop
  • Yes, you can and on javaskript of course. I hadn’t even steamed with a translation before - I just screwed a googol translator to the site, and there any page in any language. then, after all, he remade the site for Java, because it has more other possibilities, which are not available in javascript. - Drakonoved

2 answers 2

You can put the language code in the cookie or localStorage and then insert it into the links. In such links you can put a "template" ala /r2fbt.ru/---lang---/biography.html and then on the page load, replace the template like this:

 var lang = 'ru'; $('a').each(function(i, el) { el.href = el.href.replace('---lang---', lang); }); 

So doing bad , wrong and better to use either the server page generation already with the language, or some modern framework ala ReactJS or Angular. But as a temporary solution, it may be suitable.

  • one
    If you yourself understand that "doing so badly is wrong ...", then why give such advice? - Alexey Filatov
  • @AlekseyFilatov I gave a crutch, which can be temporarily used. And warned that this is a crutch, which should be temporary - Vitaly Zaslavsky

Solved the problem as follows:

 <?php require_once ('langmem.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Biography R2FBT</title> <meta name="keywords" content="biography amateur radio station" /> <meta name="description" content="Biography R2FBT" /> <link href="/r2fbt.ru/style.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="bg"> <div id="main"> <!-- header begins --> <div id="header"> <ul class="menu-main"> <li><a href="/r2fbt.ru/index.php" class="but" title="">HOME</a> </li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/biography.php" class="but_t" title="">BIOGRAPHY</a></li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/eqipment.php" class="but" title="">EQIPMENT</a></li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/qsl.php" class="but" title="">QSL</a></li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/logbook.php" class="but" title="">LOGBOOK</a></li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/dx_cluster.php" class="but" title="">DX CLUSTER</a></li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/rbn_map.php" class="but" title="">RBN map</a></li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/rbn_graph.php" class="but" title="">RBN on graph</a></li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/products.php" class="but" title="">PRODUCTS</a></li> <li><a href="/r2fbt.ru/<?php echo $lang ?>/contacts.php" class="but" title="">CONTACTS</a></li> </ul> </div> <form class="language-select" action="/r2fbt.ru/<?php echo $lang ? >/biography.php" method="post"> <input style="background: url('/r2fbt.ru/images/en.png') no-repeat left center; height: 30px; width: 60px;" type="submit" name="en" value="" /> <input style="background: url('/r2fbt.ru/images/ru.png') no-repeat left center; height: 30px; width: 60px;" type="submit" name="ru" value="" /> </form> <!-- header ends --> ..................................... ..................................... 

langmem.php

 <?php if (!isset($_session)) session_start(); $_session['lang'] = 'en'; if (isset($_POST['ru'])) $_session['lang'] = 'ru'; $lang = $_session['lang']; ?> 

It works only with reloading the page and to switch the language to the flag of the desired language you need to click 2 times.