Cookie consent when i18n ready

This commit is contained in:
vjrj 2018-01-24 19:35:55 +01:00
parent 8f73025215
commit 4674b48069
2 changed files with 11 additions and 4 deletions

View file

@ -2,6 +2,7 @@
import i18n from 'i18next';
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { ReactiveVar } from 'meteor/reactive-var';
import backend from 'i18next-xhr-backend';
import LngDetector from 'i18next-browser-languagedetector';
import Cache from 'i18next-localstorage-cache';
@ -28,6 +29,8 @@ const detectorOptions = {
excludeCacheFor: ['cimode'] // languages to not persist (cookie, localStorage)
};
export const i18nReady = new ReactiveVar(false);
const cacheOptions = {
// turn on or off
enabled: false,
@ -68,6 +71,7 @@ i18n.use(backend)
console.error(err);
return;
}
i18nReady.set(true);
document.title = t('AppName');
// Accounts translation
// https://github.com/softwarerero/meteor-accounts-t9n
@ -86,7 +90,7 @@ i18n.use(backend)
showLink: false,
position: 'bottom',
linkText: 'Lee más',
linkRouteName: '/',
linkRouteName: '/privacy',
acceptButtonText: 'Aceptar',
html: false,
expirationInDays: 70,

View file

@ -12,7 +12,7 @@ import { Roles } from 'meteor/alanning:roles';
// https://github.com/gadicc/meteor-blaze-react-component/
import Blaze from 'meteor/gadicc:blaze-react-component';
// i18n
import i18n from '/imports/startup/client/i18n';
import i18n, { i18nReady } from '/imports/startup/client/i18n';
import '/imports/startup/client/ravenLogger';
import '/imports/startup/client/geolocation';
import '/imports/startup/client/piwik-start.js';
@ -88,8 +88,9 @@ const App = props => (
</Grid>
<Footer />
<Reconnect />
{props.i18nReady.get() &&
<Blaze template="cookieConsent" />
{/* <Blaze template="cookieConsentImply" /> */}
}
</div> : ''}
</Router>
</I18nextProvider>
@ -102,6 +103,7 @@ App.defaultProps = {
App.propTypes = {
loading: PropTypes.bool.isRequired,
i18nReady: PropTypes.object.isRequired,
userId: PropTypes.string,
emailAddress: PropTypes.string,
emailVerified: PropTypes.bool.isRequired
@ -119,10 +121,11 @@ export default withTracker(() => {
const loading = !Roles.subscription.ready();
const name = user && user.profile && user.profile.name && getUserName(user.profile.name);
const emailAddress = user && user.emails && user.emails[0].address;
console.log(`i18n ready?: ${i18nReady.get()}`);
return {
loading,
loggingIn,
i18nReady,
authenticated: !loggingIn && !!userId,
name: name || emailAddress,
roles: !loading && Roles.getRolesForUser(userId),