Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.5 kB
4
Indexable
Never
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');

// Read the updated translations from the CSV file
const csvFilePath = 'translations_new.csv';
const translations = {};

const readStream = fs.createReadStream(csvFilePath, 'utf-8');

readStream.on('data', (chunk) => {
	const lines = chunk.split('\n');
	lines.forEach((line) => {
		const [key, ...values] = line.split(',');
		translations[key] = values.map((value) => value.trim());
	});
});

readStream.on('end', () => {
	updateTranslationFiles(translations);
});

// Function to update the translation JSON files
function updateTranslationFiles(translations) {
	const languages = ['en', 'de', 'fr', 'nl', 'ko', 'it'];

	languages.forEach((language) => {
		const translationFilePath = path.join(
			__dirname,
			`src/core/locales/${language}/translation.json`
		);

		try {
			const translationData = JSON.parse(fs.readFileSync(translationFilePath, 'utf-8'));

			Object.keys(translations).forEach((key) => {
				if (translationData.hasOwnProperty(key)) {
					translationData[key] = translations[key][languages.indexOf(language)];
				}
			});

			fs.writeFileSync(translationFilePath, JSON.stringify(translationData, null, 2), 'utf-8');
			console.log(`Translation file updated for ${language}`);
		} catch (error) {
			console.error(`Error updating translation file for ${language}: ${error.message}`);
		}
	});
}