-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #954 from Web3Auth/feat/loader
Feat/loader
- Loading branch information
Showing
66 changed files
with
26,367 additions
and
20,282 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,58 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable promise/always-return */ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
/* eslint-disable promise/always-return */ | ||
const https = require("https"); | ||
const fetch = require("node-fetch"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const log = require("loglevel"); | ||
|
||
const localeUrl = "https://api.tor.us/locales/web3auth"; | ||
// const localeUrl = "http://localhost:2020/locales/web3auth"; | ||
const args = process.argv.slice(2); | ||
const branch = args[0] || "main"; | ||
const repoUrl = `https://raw.githubusercontent.com/Web3Auth/web3auth-locales/${branch}/Web3Auth-locale`; | ||
const localeGroups = ["locale-common"]; | ||
const promises = []; | ||
const locales = {}; | ||
|
||
function getLocale() { | ||
return new Promise((resolve, reject) => { | ||
const request = https.get(`${localeUrl}`, (response) => { | ||
let body = ""; | ||
response.on("data", (data) => { | ||
body += data; | ||
}); | ||
response.on("end", () => { | ||
resolve(JSON.parse(body)); | ||
}); | ||
}); | ||
localeGroups.forEach((group) => { | ||
const urlFetch = `${repoUrl}/${group}.json`; | ||
promises.push(fetch(urlFetch).then((res) => res.json())); | ||
}); | ||
|
||
request.on("error", (error) => { | ||
reject(error); | ||
function processRecords(items) { | ||
Object.keys(items).forEach((groupKey) => { | ||
Object.keys(items[groupKey]).forEach((wordKey) => { | ||
Object.keys(items[groupKey][wordKey]).forEach((localeKey) => { | ||
if (!locales[localeKey]) locales[localeKey] = {}; | ||
if (!locales[localeKey][groupKey]) locales[localeKey][groupKey] = {}; | ||
locales[localeKey][groupKey][wordKey] = items[groupKey][wordKey][localeKey]; | ||
}); | ||
}); | ||
|
||
request.end(); | ||
}); | ||
} | ||
|
||
getLocale() | ||
.then((result) => { | ||
const locales = result.data; | ||
const folders = ["./packages/ui/src/i18n/"]; | ||
folders.forEach((folder) => { | ||
const folderPath = path.resolve(folder); | ||
|
||
if (!fs.existsSync(folderPath)) { | ||
fs.mkdirSync(folderPath); | ||
} | ||
Promise.all(promises) | ||
.then((results) => { | ||
results.forEach((set) => { | ||
processRecords(set); | ||
}); | ||
|
||
// Create json files | ||
const folder = "./packages/ui/src/i18n/"; | ||
const folderPath = path.resolve(folder); | ||
if (!fs.existsSync(folderPath)) { | ||
fs.mkdirSync(folderPath); | ||
} | ||
|
||
const keys = Object.keys(locales); | ||
for (const localeKey of keys) { | ||
if (Object.prototype.hasOwnProperty.call(locales, localeKey)) { | ||
folders.forEach((folder) => { | ||
const filePath = path.resolve(`${folder}${localeKey}.json`); | ||
fs.writeFile(filePath, JSON.stringify(locales[localeKey], null, 2), { flag: "w" }, (error) => { | ||
if (error) throw error; | ||
}); | ||
const filePath = path.resolve(`${folder}${localeKey}.json`); | ||
fs.writeFile(filePath, JSON.stringify(locales[localeKey], null, 2), { flag: "w" }, (error) => { | ||
if (error) throw error; | ||
}); | ||
} | ||
} | ||
}) | ||
.catch((error) => { | ||
log.error(error); | ||
console.error(error); | ||
}); |
Oops, something went wrong.