Last active
January 27, 2017 17:23
-
-
Save heneryville/bc98b4886f25ce30e664f477f8af3332 to your computer and use it in GitHub Desktop.
i18next interleaving race condition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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