Open josher19 opened 4 years ago
PS: There is an ugly work-around, but it is not very efficient.
You can delete the cache and re-require casual for each language/locale:
function refresh(moduleName = 'casual') {
delete require.cache[require.resolve(moduleName)];
Object.keys(require.cache)
.filter(pathName => pathName && pathName.indexOf(moduleName) !== -1)
.forEach(pathName => delete require.cache[pathName]);
return require(moduleName);
}
const getLang = lang => refresh()[lang];
Example usage showing the problem:
const casual = require('casual');
casual.seed(41)
casual.ar_SY.city // Arabic, as expected, but followed by
casual.de_DE.city // now Arabic instead of German?
getLang('ar_SY').city;
getLang('de_DE').city; // German, not Arabic
@boo1ean Right now
casual
locales are broken ... importing one pollutes parts of the global namespace in casual which then causes strange results, like Arabic showing up in German addresses when usingcasual.ar_SY
andcasual.de_DE
Example failing test: https://gist.github.com/josher19/c4a0450d1eede980342a9e4010c72845
Perhaps Related: #8 and #77