JavaScript
Article

jQuery Rotate Through Other Languages

By Sam Deering

text-changes-automatically

jQuery code snippet to show other languages link (say in the footer) of your web page. It randomly shows other languages available with a link to change the language of the website. It is set to change every 5 seconds but this can be optimised as well as the array of languages displayed.

jQuery Code

(function (b) {
	var c = ['العربية', 'Ελληνικά', 'Polski', 'Bosanksi', 'Bahasa Indonesia', 'Русский', '中文', 'Italiano', 'српски', 'Hrvatski', '日本語', 'Español', 'Français', '한국어', 'Tagalog', 'Deutsch', 'فارسی', 'Tiếng Việt'];
	var a = document.doctype ? document.doctype.publicId : document.firstChild.data;
	var d = a.indexOf("XHTML") > 0;
	updateLanguage = function () {
		b("#languages a").empty().append(c[Math.floor(Math.random() * c.length)] + " (Other languages)");
		if (d) {
			b("#languages span").attr("xml:lang", b("#languages span").attr("lang"))
		}
	};
	updateLanguage();
	window.setInterval(updateLanguage, 5000)
})(jQuery)

HTML Code

  • Other languages
  • No Reader comments

    Recommended
    Sponsors
    Because We Like You
    Free Ebooks!

    Grab SitePoint's top 10 web dev and design ebooks, completely free!

    Get the latest in JavaScript, once a week, for free.