Add Docker build and deploy pipeline
Some checks failed
deploy-frontend / deploy (push) Failing after 11s
Some checks failed
deploy-frontend / deploy (push) Failing after 11s
This commit is contained in:
34
src/i18n.js
Normal file
34
src/i18n.js
Normal file
@@ -0,0 +1,34 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import translationRU from './locales/ru.json';
|
||||
import translationEN from './locales/en.json';
|
||||
|
||||
const LANGUAGES = ['ru', 'en'];
|
||||
|
||||
// i18next-browser-languagedetector в проекте нет, поэтому persist делаем сами:
|
||||
// иначе выбор языка жил только в памяти и сбрасывался при перезагрузке.
|
||||
const stored = localStorage.getItem('i18nextLng');
|
||||
const savedLang = LANGUAGES.includes(stored) ? stored : 'ru';
|
||||
|
||||
i18n.use(initReactI18next).init({
|
||||
resources: {
|
||||
ru: { translation: translationRU },
|
||||
en: { translation: translationEN },
|
||||
},
|
||||
lng: savedLang,
|
||||
fallbackLng: 'ru',
|
||||
supportedLngs: LANGUAGES,
|
||||
interpolation: { escapeValue: false },
|
||||
});
|
||||
|
||||
const updateDocumentTitle = (lng) => {
|
||||
document.title = lng === 'en' ? 'Find' : 'Находка';
|
||||
};
|
||||
|
||||
i18n.on('languageChanged', (lng) => {
|
||||
localStorage.setItem('i18nextLng', lng);
|
||||
updateDocumentTitle(lng);
|
||||
});
|
||||
updateDocumentTitle(i18n.language);
|
||||
|
||||
export default i18n;
|
||||
Reference in New Issue
Block a user