How to Translate your Site in Runtime using jQuery

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml&#8221; xml:lang=”en”>
<head>
<title>How to Translate your Site in Runtime using Jquery – demo</title>
<link rel=”stylesheet” href=”css/main.css” type=”text/css” />
http://js/jquery.min.js
http://js/main.js
</head>
<body>

How to Translate your Site in Runtime using Jquery – demo

EN
RU

<!– nav menu start –>
<ul id=”nav”>
<li><a href=”#nogo” key=”home” class=”tr”>Home</a></li>
<li><a href=”#nogo” key=”peoples” class=”tr”>Peoples >></a>
<ul>
<li><a href=”#nogo” key=”all_list” class=”tr”>All list</a></li>
<li><a href=”#nogo” key=”online” class=”tr”>Online</a></li>
</ul>
</li>
<li><a href=”#nogo” key=”articles” class=”tr”>Articles >></a>
<ul>
<li><a href=”#nogo” key=”js” class=”tr”>JavaScript</a></li>
<li><a href=”#nogo” key=”php” class=”tr”>PHP</a></li>
<li><a href=”#nogo” key=”html” class=”tr”>HTML</a></li>
<li><a href=”#nogo” key=”css” class=”tr”>CSS</a></li>
</ul>
</li>
<li><a href=”#nogo” key=”contact_us” class=”tr”>Contact us</a></li>
</ul>
<!– nav menu end –>

<h2 key=”welcome” class=”tr”>Welcome guests</h2>
<hr />

A man bribes a rabbit with wicked dentures to run away with him in a sailboat via an ambulance. Bribing Koalas to remain illegally in one place. Trees anchor me in place. / Your mom drives the ambulance, but the city is farther than it appears.

</div>
</div>
</body>
</html>

 

// preparing language file
var aLangKeys=new Array();
aLangKeys[‘en’]=new Array();
aLangKeys[‘ru’]=new Array();
aLangKeys[‘en’][‘home’]=’Home’;
aLangKeys[‘en’][‘peoples’]=’Peoples >>’;
aLangKeys[‘en’][‘all_list’]=’All list’;
aLangKeys[‘en’][‘online’]=’Online’;
aLangKeys[‘en’][‘articles’]=’Articles >>’;
aLangKeys[‘en’][‘js’]=’JavaScript’;
aLangKeys[‘en’][‘php’]=’PHP’;
aLangKeys[‘en’][‘html’]=’HTML’;
aLangKeys[‘en’][‘css’]=’CSS’;
aLangKeys[‘en’][‘contact_us’]=’Contact us’;
aLangKeys[‘en’][‘welcome’]=’Welcome guests’;
aLangKeys[‘ru’][‘home’]=’Главная’;
aLangKeys[‘ru’][‘peoples’]=’Пользователи >>’;
aLangKeys[‘ru’][‘all_list’]=’Весь список’;
aLangKeys[‘ru’][‘online’]=’В сети’;
aLangKeys[‘ru’][‘articles’]=’Статьи >>’;
aLangKeys[‘ru’][‘js’]=’Яваскрипт’;
aLangKeys[‘ru’][‘php’]=’ПХП’;
aLangKeys[‘ru’][‘html’]=’ХТМЛ’;
aLangKeys[‘ru’][‘css’]=’КСС’;
aLangKeys[‘ru’][‘contact_us’]=’Напишите нам’;
aLangKeys[‘ru’][‘welcome’]=’Добро пожаловать’;
$(document).ready(function() {
// onclick behavior
$(‘.lang’).click( function() {
var lang = $(this).attr(‘id’); // obtain language id
// translate all translatable elements
$(‘.tr’).each(function(i){
$(this).text(aLangKeys[lang][ $(this).attr(‘key’) ]);
});
} );
});

 

https://www.script-tutorials.com/how-to-translate-your-site-in-runtime-using-jquery/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s