Skip to content

Instantly share code, notes, and snippets.

@dev-sampsonorson
Created June 16, 2023 18:02
Show Gist options
  • Save dev-sampsonorson/6471fc8f8e18d95faab67071317d5119 to your computer and use it in GitHub Desktop.
Save dev-sampsonorson/6471fc8f8e18d95faab67071317d5119 to your computer and use it in GitHub Desktop.
const language = detectVisitorLanguage();
// - import(someVariable) is not supported; it must be a constant
// - Some path must be specified
// - We can specify a directory or set of files
// - Everything that could be requested (potentially match that path) is included (in the bundle during build time)
// https://webpack.js.org/api/module-methods/#dynamic-expressions-in-import
import(`./locale/${language}.json`).then((module) => {
// do something with the translation
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment