This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
forked from i18nlaurel/Web3-Glossary
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #8 from mapachurro/rename-defs
Rename defs
- Loading branch information
Showing
38 changed files
with
11,462 additions
and
2,044 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const termsFilePath = path.join(__dirname, './consensys-termbase.json'); | ||
const localesDir = path.join(__dirname, './../src/i18n', 'locales'); | ||
|
||
const termsData = JSON.parse(fs.readFileSync(termsFilePath, 'utf8')); | ||
|
||
for (const term of termsData) { | ||
const i18nData = Object.entries(term).filter(([key]) => key !== 'Term' && key !== 'Definition' && key !== 'Term category'); | ||
|
||
for (const [locale, translation] of i18nData) { | ||
const localeDir = path.join(localesDir, locale.toLowerCase()); | ||
const translationFilePath = path.join(localeDir, 'translation.json'); | ||
|
||
try { | ||
// Create the locale directory if it doesn't exist | ||
if (!fs.existsSync(localeDir)) { | ||
fs.mkdirSync(localeDir, { recursive: true }); | ||
console.log(`Created directory: ${localeDir}`); | ||
} | ||
|
||
// Read the existing translation file or create a new one | ||
let translationData = {}; | ||
if (fs.existsSync(translationFilePath)) { | ||
translationData = JSON.parse(fs.readFileSync(translationFilePath, 'utf8')); | ||
} else { | ||
fs.writeFileSync(translationFilePath, '{}'); | ||
console.log(`Created file: ${translationFilePath}`); | ||
} | ||
|
||
// Add or update the term translation in the translation data | ||
translationData[term.Term] = translation; | ||
|
||
// Write the updated translation data to the file | ||
fs.writeFileSync(translationFilePath, JSON.stringify(translationData, null, 2)); | ||
console.log(`Added term "${term.Term}" to ${translationFilePath}`); | ||
} catch (err) { | ||
console.error(`Error processing term "${term.Term}" for locale "${locale}":`, err); | ||
} | ||
} | ||
} |
Oops, something went wrong.