Change language


I am trying to build a functionality that will change the language in a web page using only Javascript.
Ideally, I would like to have an external txt file that will be imported in H2 and P tags inside the page.

Is this possible or I have to use PHP or something else?

Thank you!

I don’t think this is a good solution.

Why don’t you use different HTML files instead of trying to replace text in one? When you replace text you never know how the layout of the page is changing in case of languages with much longer texts. Or what about Arabian languages where you read from the right to the left?

I would create a HTML page for each language and load the correct file depending on the selected language.

Of course these HTML file should only contain the HTML no PHP or JS inside. In that case its easy for any translation company to translate the text by using a html wysiwyg editor

1 Like

yeah that will be a good solution indeed, but I want a customer to be able to change the text in these languages and he is not a dev.
So I am looking for a very simple way to do it, like having an external txt file.

There are several ways to achieve this. But AFAIK there is no both simple and cheap solution.

I have done a draft of this using .po files (close to .txt). There are one .po file for each language. And the html template is using the po files as “lookup” tables from a script within the template.

I guess this is doable also using PHP or whatever language you are using.

I think the simplest solution is what @Thallius suggested. Using Wordpress, the user can edit the text in a simple way.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.