2017-04-30 14:35:07 +00:00
|
|
|
/* global fetch */
|
|
|
|
import 'isomorphic-fetch'
|
|
|
|
|
2017-08-13 00:28:20 +00:00
|
|
|
/**
|
|
|
|
* Fetch translation file(s).
|
|
|
|
* @function getTranslation
|
|
|
|
* @param {string} lang - Language to fetch.
|
|
|
|
* @param {array} files - Translation files to fetch.
|
|
|
|
* @param {string} baseUrl - Locale location.
|
|
|
|
* @return {object} Fetched translation files.
|
|
|
|
*/
|
|
|
|
export async function getTranslation (lang, files, baseUrl) {
|
|
|
|
let translation = {}
|
2017-04-30 14:35:07 +00:00
|
|
|
|
2017-08-13 00:28:20 +00:00
|
|
|
for (let file of files) {
|
|
|
|
const response = await fetch(`${baseUrl}${lang}/${file}.json`)
|
|
|
|
translation[file] = await response.json()
|
2017-04-30 14:35:07 +00:00
|
|
|
}
|
2017-08-13 00:28:20 +00:00
|
|
|
|
|
|
|
return { [lang]: translation }
|
2017-04-30 14:35:07 +00:00
|
|
|
}
|