Skip to content

Commit

Permalink
Merge pull request #418 from torusresearch/feat/locale-github
Browse files Browse the repository at this point in the history
feat: export locales from github
  • Loading branch information
metallicalfa2 authored Dec 5, 2022
2 parents 43a5f1f + 73160b2 commit feaedfa
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 57 deletions.
25 changes: 19 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test:controller": "npx mocha ./tests/controller/**.ts",
"test:report": "rm -rf .nyc_output && rm -rf coverage && npx nyc --reporter=text --reporter=html npm run test:controller",
"install:local": "npm i ../controllers/packages/solana-controllers/*.tgz && npm i ../controllers/packages/base-controllers/*.tgz",
"locale": "node ./src/scripts/importLocales.js",
"locale": "node ./src/scripts/importLocales.mjs",
"serve:prod": "vue-cli-service serve --mode production"
},
"dependencies": {
Expand Down Expand Up @@ -136,6 +136,7 @@
"lint-staged": "^12.4.3",
"mocha": "^10.0.0",
"nock": "^13.2.9",
"node-fetch": "^2.6.7",
"nyc": "^15.1.0",
"os-browserify": "^0.3.0",
"postcss": "^8.4.16",
Expand Down
50 changes: 0 additions & 50 deletions src/scripts/importLocales.js

This file was deleted.

70 changes: 70 additions & 0 deletions src/scripts/importLocales.mjs
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);
});

0 comments on commit feaedfa

Please sign in to comment.