Answer the question
In order to leave comments, you need to log in
How to implement multilingualism on the site?
Good
afternoon, tell me, the site is made on React, but the base is written in php.
It is necessary to implement a site for 2 versions in Russian. and Ukrainian
The code should display both Russian and Ukrainian versions, but at the same time, when you select a language on the site, it pulls up a certain description.
There is a Hotline website (here's something to do) when they switch the language, only the text changes.
Answer the question
In order to leave comments, you need to log in
1. In the store, you control which language is selected
2. In the store, you pull a dictionary with the active language from the back
3. In the store, a function that accepts a tag for translation and returns the text
like this:
activeLang = 'ru' // активный язык
dict = [
{tag: 'header-title', ru:'Зонтик', ua: 'Парасолька'}
] // пример словаря котрый мы получили с бэка и положили в стор
const getMyLocal = tag =>{
const item = dict.find((item) => item.tag === tag );
return item ? item[activeLang] : 'wrong tag';
}
<div>getMyLocal('header-title') </div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question