Added user lang setting
This commit is contained in:
parent
fc56bd3273
commit
97c47c5d1d
7 changed files with 90 additions and 21 deletions
|
|
@ -1,6 +1,7 @@
|
|||
/* global CookieConsent Intl */
|
||||
import i18n from 'i18next';
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Tracker } from 'meteor/tracker';
|
||||
import backend from 'i18next-xhr-backend';
|
||||
import LngDetector from 'i18next-browser-languagedetector';
|
||||
import Cache from 'i18next-localstorage-cache';
|
||||
|
|
@ -98,6 +99,22 @@ i18n.use(backend)
|
|||
i18n.on('languageChanged', (lng) => {
|
||||
moment.locale(lng);
|
||||
T9n.setLanguage(lng);
|
||||
Tracker.autorun(() => {
|
||||
if (Meteor.userId()) {
|
||||
// logged
|
||||
if (Meteor.user() && (typeof Meteor.user().lang === 'undefined' ||
|
||||
Meteor.user().lang !== lng)
|
||||
) {
|
||||
// Set the autodetected/changed lang
|
||||
console.log(`Setting the autodetected lang ${lng}`);
|
||||
Meteor.call('users.setLang', lng, (error) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
|
|
|
|||
|
|
@ -20,14 +20,8 @@ const shouldDebug = (forceDebug && !Meteor.isProduction);
|
|||
|
||||
const i18nOpts = {
|
||||
backend: backOpts,
|
||||
lng: 'es',
|
||||
// fallbackLng: 'es',
|
||||
fallbackLng: {
|
||||
'en-US': ['en'],
|
||||
'en-GB': ['en'],
|
||||
'pt-BR': ['pt'],
|
||||
default: ['es']
|
||||
},
|
||||
// lng: 'es',
|
||||
fallbackLng: ['es', 'en'],
|
||||
interpolation: {
|
||||
escapeValue: false, // not needed for react!!
|
||||
formatSeparator: ',',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue