satya satya - 6 months ago 59
AngularJS Question

How to support multi language to my HTML page using Angular.js/Javascript

I need one help.I need to change language my All text present inside my HTML page dynamically using Angular.js/Javascript. I am explaining my code or scenario below.

<h2>Clickable Dropdown</h2>
<p>Click on the button to open the dropdown menu.</p>
<option value="">Select langauage</option>
<option value="1">English</option>
<option value="2">Spanish</option>
First name:<br>
<input type="text" name="firstname" placeholder="firstname"><br>
Last name:<br>
<input type="text" name="lastname" placeholder="lastname">

Above one drop down is present to select different language .Here my requirement is suppose user selected language as
all static text present over there will change to spanish language and if user will again select
the all data will re change to english. Please help me.


You can use the standard HTML lang attribute:

<span lang="en">Scale</span><span lang="de">MaƟstab</span>

And then you can hide and show the matching elements:

function select_language(language) {
    $("[lang]").each(function () {
        if ($(this).attr("lang") == language)

I use a simple selection:

<select onchange="select_language(this.options[this.selectedIndex].value)">
  <option value="en" selected>English</option>
  <option value="de">Deutsch</option>

Other Option

Translate Content in JavaScript an HTML with the Google Translate API