/    Sign up×
Community /Pin to ProfileBookmark

Trying to implement a multi-lingual site

I’m trying to implement a multi-lingual site where the user would have the option to pick a language.

I got an example from here:[url]https://codepen.io/codepajamas/pen/NjGOMV[/url]
but when I apply the code with some small modifications, it fails to switch the language. I basically want to be able to change the language of all <p>, <H1-6> and <li> elements.

What am I doing wrong? ?

Here’s my modified code in JSfiffle: [url]https://jsfiddle.net/hgbaLy6e/[/url]

Code:

[code=html]<!DOCTYPE html>
<html>
<head>
<title>About this site</title>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no”>
<link rel =”stylesheet” href=”2.css”>
</head>
<body>

<h3>Change language</h3>
<select id=”lang-switch”>
<option value=”en”>English</option>
<option value=”fr”>Francais</option>
<option value=”es”>español</option>
</select>

<p lang=”en”>Hi!</p>
<p lang=”fr”>Bonjour!</p>
<p lang=”es”>Holla!</p>

</body>
<script src=”2.js”>
</script>

</html>[/code]

[CODE][lang=”fr”],
[lang=”es”] {
display: none;
}

html{background-color:black; color:white; }[/CODE]

[CODE]$(‘[lang=”fr”]’).hide();
$(‘[lang=”es”]’).hide();

$(‘#lang-switch’).change(function () {
var lang = $(this).val();
switch (lang) {
case ‘en’:
$(‘[lang]’).hide();
$(‘[lang=”en”]’).show();
break;
case ‘fr’:
$(‘[lang]’).hide();
$(‘[lang=”fr”]’).show();
break;
case ‘es’:
$(‘[lang]’).hide();
$(‘[lang=”es”]’).show();
break;
default:
$(‘[lang]’).hide();
$(‘[lang=”en”]’).show();
}
});[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottNov 04.2017 — Console says $ is not defined. You forgot to load jQuery.
×

Success!

Help @John-footer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...