Files
freeCodeCamp/tools/crowdin/actions/hide-non-translated-strings/index.js
renovate[bot] 21dd80c47a chore(deps): update dependency prettier to v2.3.0 (#42074)
* chore(deps): update dependency prettier to v2.3.0

* chore: apply formating per prettier

* fix: correctly disable import/no-unresolved

Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Mrugesh Mohapatra <hi@mrugesh.dev>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
2021-05-10 08:48:49 -07:00

63 lines
1.6 KiB
JavaScript

require('dotenv').config({ path: `${__dirname}/../../.env` });
const fs = require('fs');
const path = require('path');
const matter = require('gray-matter');
const { getFiles } = require('../../utils/files');
const { getStrings, updateFileString } = require('../../utils/strings');
const createChallengeTitleLookup = (
lookup,
{ fileId, path: crowdinFilePath }
) => {
const challengeFilePath = path.join(
__dirname,
'/../../../../',
crowdinFilePath
);
try {
const challengeContent = fs.readFileSync(challengeFilePath);
const {
data: { title: challengeTitle }
} = matter(challengeContent);
return {
...lookup,
[fileId]: {
crowdinFilePath,
challengeTitle
}
};
} catch (err) {
console.log(err.name);
console.log(err.message);
}
return lookup;
};
const hideNonTranslatedStrings = async projectId => {
console.log('hide non-translated strings...');
const crowdinFiles = await getFiles(projectId);
if (crowdinFiles && crowdinFiles.length) {
const challengeTitleLookup = crowdinFiles.reduce(
createChallengeTitleLookup,
{}
);
const crowdinStrings = await getStrings({ projectId });
if (crowdinStrings && crowdinStrings.length) {
for (let string of crowdinStrings) {
const { crowdinFilePath, challengeTitle } =
challengeTitleLookup[string.data.fileId];
await updateFileString({
projectId,
string,
challengeTitle,
crowdinFilePath
});
}
}
}
console.log('complete');
};
const projectId = process.env.CROWDIN_PROJECT_ID;
hideNonTranslatedStrings(projectId);