I need to make landing page on 2 languages, swapping language by click on the flag.
How I understand, I need to save language state in user's localstorage / cookies.
I see here 3 options:
Upload on user machine .json with content on 2 languages. At the opening of page script will check localstorage for availability of lang variable and after it fill page by JS.
Save lang variable in cookies, and at appeal to the server, server must make magic and send back page built on user language.
Make duplicates of each page in each language.
Question 1:
Which way better, when and why? (cases: one page landing, site with many pages)
Question 2:
When I make duplicates of page, is it normal to have no index.html
in root directory at all, but:
/en/index.html
/ru/index.html
and .htaccess
file that redirect to /en/
by default, check cookies for lang variable, and if exist redirect user to specific folder.
Question 1: Option 1: Good practice if you have some sort of frontend framework (like Angular or React). But if you have a static (or only serverside rendering) page it is not really the way to go. Because it add unnecessary complexity to your code.
Option 2: Good way to do it if you only have backend rendering (for example with PHP).
Option 3: Do this only if you have static webpage (only HTML/CSS) which does not change. And you don't have programming experience at all.
Question 2: Well no you always have a index.html but you can redirect to the index.html of the default language.