I
I
IartanisI2015-11-18 10:33:11
Web development
IartanisI, 2015-11-18 10:33:11

Changing the language on the site?

Sorry for the possibly stupid question, but how to organize the language change on the site? To be more precise, I have a website in javascript, and I need to make an English and Russian version. It is clear that you can simply duplicate the pages, or can it be done differently, more efficiently?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2015-11-18
@IartanisI

1. Define the language:
2. We load the dynamically required js containing an associative array of string constants for the current language. Use for simplicity: www.javascriptkit.com/javatutors/loadjavascriptcss...
3. Use array elements on the page.
UPD: 4. It is possible to replace DOM container strings through a function using a Regex template in order not to use template elements in the original "body" of the page, but to keep the usual text strings of the "home" language.

D
Dmitry Kovalsky, 2015-11-18
@dmitryKovalskiy

Well, there are a few subtleties here. In the general case, you need a markup template where text zones will be marked with some variables, and when the page is rendered to the client, these variables are replaced from some resources with the desired text. This is implemented differently on different platforms - check your technology stack and perhaps the advice will be more specific. Regarding subtleties.
1) Different languages ​​have different average word lengths, which is why layout of a text container can be a very interesting process.
2) There are languages ​​that have a different direction of writing, in comparison with Russian. This requires serious modifications to the template, up to the second template for similar languages.
3) In addition to the words themselves - in different regions of the world, finances, dates and some other non-verbal data are displayed differently. For example, decimal point in numbers, date separators, 07/08/09 - Can you tell me what date I mean?
I hope colleagues will supplement the list of subtleties with their personal experience.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question