mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-02-01 14:44:05 +00:00
feat: improve clean-translations script (#964)
This commit is contained in:
committed by
GitHub
parent
719cb11d44
commit
9fcede5729
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { execSync } = require('child_process');
|
|
||||||
|
|
||||||
// Get the root directory (where the script is run from)
|
// Get the root directory (where the script is run from)
|
||||||
const rootDir = process.cwd();
|
const rootDir = process.cwd();
|
||||||
@@ -72,24 +71,24 @@ function removeEmptyStrings(obj) {
|
|||||||
* Process a single JSON file to remove empty strings
|
* Process a single JSON file to remove empty strings
|
||||||
* @param {string} filePath - Path to the JSON file
|
* @param {string} filePath - Path to the JSON file
|
||||||
*/
|
*/
|
||||||
function processFile(filePath) {
|
async function processFile(filePath) {
|
||||||
try {
|
try {
|
||||||
console.log(`Processing ${filePath}`);
|
console.log(`Processing ${filePath}`);
|
||||||
|
|
||||||
// Read and parse the JSON file
|
// Read and parse the JSON file
|
||||||
const data = fs.readFileSync(filePath, 'utf8');
|
const data = await fs.promises.readFile(filePath, 'utf8');
|
||||||
const json = JSON.parse(data);
|
const json = JSON.parse(data);
|
||||||
|
|
||||||
// Clean the JSON data
|
// Clean the JSON data
|
||||||
const cleanedJson = removeEmptyStrings(json);
|
const cleanedJson = removeEmptyStrings(json);
|
||||||
|
|
||||||
// Write the cleaned JSON back to the file
|
// Write the cleaned JSON back to the file
|
||||||
fs.writeFileSync(
|
await fs.promises.writeFile(
|
||||||
filePath,
|
filePath,
|
||||||
JSON.stringify(cleanedJson, null, '\t'),
|
JSON.stringify(cleanedJson, null, '\t'),
|
||||||
'utf8'
|
'utf8'
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(`Successfully cleaned ${filePath}`);
|
console.log(`Successfully cleaned ${filePath}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error processing ${filePath}:`, error);
|
console.error(`Error processing ${filePath}:`, error);
|
||||||
@@ -99,26 +98,28 @@ function processFile(filePath) {
|
|||||||
/**
|
/**
|
||||||
* Process all JSON files in the specified directories
|
* Process all JSON files in the specified directories
|
||||||
*/
|
*/
|
||||||
function main() {
|
async function main() {
|
||||||
directories.forEach(dir => {
|
for (const dir of directories) {
|
||||||
if (!fs.existsSync(dir)) {
|
try {
|
||||||
|
await fs.promises.access(dir);
|
||||||
|
} catch {
|
||||||
console.warn(`Directory ${dir} does not exist. Skipping.`);
|
console.warn(`Directory ${dir} does not exist. Skipping.`);
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const files = fs.readdirSync(dir);
|
const files = await fs.promises.readdir(dir);
|
||||||
|
|
||||||
files.forEach(file => {
|
for (const file of files) {
|
||||||
const filePath = path.join(dir, file);
|
const filePath = path.join(dir, file);
|
||||||
|
|
||||||
if (file.endsWith('.json') && file !== 'en.json') {
|
if (file.endsWith('.json') && file !== 'en.json') {
|
||||||
processFile(filePath);
|
await processFile(filePath);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
console.log('All translation files have been processed successfully!');
|
console.log('All translation files have been processed successfully!');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the script
|
// Run the script
|
||||||
main();
|
main();
|
||||||
|
|||||||
Reference in New Issue
Block a user