-
Notifications
You must be signed in to change notification settings - Fork 20
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 #418 from torusresearch/feat/locale-github
feat: export locales from github
- Loading branch information
Showing
4 changed files
with
91 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import fs from "fs"; | ||
import fetch from "node-fetch"; | ||
import path from "path"; | ||
|
||
const args = process.argv.slice(2); | ||
const branch = args[0] || "main"; | ||
const repoUrl = `https://raw.githubusercontent.com/Web3Auth/web3auth-locales/${branch}/Solana-locale`; | ||
const localeGroups = [ | ||
"locales-account-menu", | ||
"locales-email-phone-login", | ||
"locales-login", | ||
"locales-nav-bar", | ||
"locales-wallet-activity", | ||
"locales-wallet-dapp", | ||
"locales-wallet-discover", | ||
"locales-wallet-home", | ||
"locales-wallet-nft", | ||
"locales-wallet-settings", | ||
"locales-wallet-spay", | ||
"locales-wallet-top-up", | ||
"locales-wallet-transfer", | ||
]; | ||
|
||
const promises = []; | ||
const locales = {}; | ||
|
||
localeGroups.forEach((group) => { | ||
const urlFetch = `${repoUrl}/${group}.json`; | ||
promises.push(fetch(urlFetch).then((res) => res.json())); | ||
}); | ||
|
||
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]; | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
Promise.all(promises) | ||
.then((results) => { | ||
results.forEach((set) => { | ||
processRecords(set); | ||
}); | ||
|
||
// Create json files | ||
const folder = "./src/plugins/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)) { | ||
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) => { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
}); |