Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
ADDED TERMS TO I18N FILES
Browse files Browse the repository at this point in the history
  • Loading branch information
mapachurro committed Apr 12, 2024
1 parent 3047246 commit 1679874
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions data/transExport.js
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);
}
}
}

0 comments on commit 1679874

Please sign in to comment.