pris
pris

Reputation: 50

Set language variable using html/js

I am currently creating on online version of a magazine. The magazine is made up of a series of html5 pages. On each page, the user is provided the choice to choose language,"En/Fr".

I would like to know how i can set the language to the chosen one for the whole magazine. For example, suppose I am on page1 and 1 choose lang 'Fr', the other pages too should be loading in Fr. And now, on page20 I choose lang 'En', all the pages should load in 'En'.

Is that possible using html/js??

Could you provide me with a solution.

Thanks

Upvotes: 0

Views: 1261

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201568

There are a few options: using a cookie, using sessionStorage or localStorage, and including language identifier in URLs (path part or query part). There is insufficient information (no info about server-side technology used etc.) to suggest a particular approach. In any case, if you want the pages to be found via search engines, each language version should have a URL of its own.

Upvotes: 0

Steve Papa
Steve Papa

Reputation: 422

This solution can't be achieved using pure javascript and html, as the variables will be lost when the page is reloaded.

You may like to investigate a solution using cookies.

For your example.

To set language:

 $.cookie("language", "fr");

To read language from cookie:

 $.cookie("language")

To delete language:

 $.cookie("language", null);

Upvotes: 1

Related Questions