2022-01-17 16:01:07 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const glob = require('glob');
|
|
|
|
|
|
|
|
const PACKAGES_DIR_PATH = 'packages/';
|
|
|
|
const TRANSLATION_FILE_PATH = '/admin/src/translations/en.json';
|
|
|
|
|
|
|
|
const getPackageNameFromPath = filePath => {
|
|
|
|
return filePath.replace(PACKAGES_DIR_PATH, '').replace(TRANSLATION_FILE_PATH, '');
|
|
|
|
};
|
|
|
|
|
|
|
|
const readTranslationFile = filePath => ({
|
|
|
|
filePath,
|
|
|
|
packageName: getPackageNameFromPath(filePath),
|
|
|
|
fileContent: JSON.parse(fs.readFileSync(filePath).toString('utf-8')),
|
|
|
|
});
|
|
|
|
|
2022-02-22 11:15:34 +01:00
|
|
|
const writeTranslationFile = file => {
|
|
|
|
fs.writeFileSync(file.filePath, JSON.stringify(file.fileContent, null, 2) + '\n');
|
|
|
|
};
|
|
|
|
|
2022-01-17 16:01:07 +01:00
|
|
|
const readAllTranslationFiles = () => {
|
|
|
|
const translationFilesPaths = [
|
|
|
|
...glob.sync(path.join(PACKAGES_DIR_PATH, 'core/*/', TRANSLATION_FILE_PATH)),
|
|
|
|
...glob.sync(path.join(PACKAGES_DIR_PATH, 'plugins/*/', TRANSLATION_FILE_PATH)),
|
|
|
|
];
|
|
|
|
|
|
|
|
return translationFilesPaths.map(readTranslationFile);
|
|
|
|
};
|
|
|
|
|
2022-02-22 11:15:34 +01:00
|
|
|
const writeAllTranslationFiles = files => {
|
|
|
|
files.forEach(writeTranslationFile);
|
|
|
|
};
|
|
|
|
|
2022-01-17 16:01:07 +01:00
|
|
|
module.exports = {
|
|
|
|
readTranslationFile,
|
2022-02-22 11:15:34 +01:00
|
|
|
writeTranslationFile,
|
2022-01-17 16:01:07 +01:00
|
|
|
readAllTranslationFiles,
|
2022-02-22 11:15:34 +01:00
|
|
|
writeAllTranslationFiles,
|
2022-01-17 16:01:07 +01:00
|
|
|
};
|