Skip to content

Instantly share code, notes, and snippets.

@heneryville
Last active January 27, 2017 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heneryville/bc98b4886f25ce30e664f477f8af3332 to your computer and use it in GitHub Desktop.
Save heneryville/bc98b4886f25ce30e664f477f8af3332 to your computer and use it in GitHub Desktop.
i18next interleaving race condition
"use strict";
var i18n = require('i18next');
const LanguageStrings = {
"en-GB": {
translation: {
"SAY_STUFF": "en-GB said"
}
},
"de-DE": {
translation: {
"SAY_STUFF": "de-DE said"
}
}
}
function randSayer(lang) {
i18n.init({
lng: lang,
resources: LanguageStrings,
returnObjects: true,
}, function(err){
scheduleNext();
});
scheduleNext();
function say() {
var expect = lang;
var actual = i18n.t('SAY_STUFF');
var mismatch = actual.indexOf(expect) != 0;
console.log(expect, actual, mismatch ? 'Mismatch!' : '' )
scheduleNext();
}
function scheduleNext() {
setTimeout(say, Math.ceil(Math.random() * 1000, + 10 ));
}
}
randSayer('en-GB');
randSayer('de-DE');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment