Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

casual locales are broken #99

Open
josher19 opened this issue Sep 15, 2020 · 1 comment
Open

casual locales are broken #99

josher19 opened this issue Sep 15, 2020 · 1 comment

Comments

@josher19
Copy link

@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 using casual.ar_SY and casual.de_DE

Example failing test:
https://gist.github.com/josher19/c4a0450d1eede980342a9e4010c72845

Perhaps Related: #8 and #77

@josher19
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant