Skip to content

Instantly share code, notes, and snippets.

@brionmario
Created March 19, 2020 09:20
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 brionmario/0de93ac58d521f2e479272bcbeeae057 to your computer and use it in GitHub Desktop.
Save brionmario/0de93ac58d521f2e479272bcbeeae057 to your computer and use it in GitHub Desktop.
export const loadResourcesAtRuntime = async (meta: SupportedLanguages, bundleLocation: string) => {
let resources: Resource = {};
for (const locale of Object.values(meta)) {
for (const [ nsKey, nsPath ] of Object.entries(locale.paths)) {
try {
const response = await fetch(`${ bundleLocation }/${ nsPath }`);
const payload = await response.json();
resources = {
...resources,
[ locale.code ]: {
...resources[ locale.code ],
[ nsKey ]: payload as any
}
}
} catch (e) {
console.log(e);
}
}
}
return resources;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment