Created
March 19, 2020 09:20
-
-
Save brionmario/0de93ac58d521f2e479272bcbeeae057 to your computer and use it in GitHub Desktop.
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
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