fix(tools): Integrate certificate and comment dictionaries into the Curriculum project on Crowdin (#40872)

* fix: integrate certificate and dictionary files to Crowdin

* fix: correct linting issue

* fix: improved the isReserveredHeading function
This commit is contained in:
Randell Dawson
2021-02-02 20:50:04 -07:00
committed by GitHub
parent 4d48fb5ce7
commit 2f207c3827
4 changed files with 83 additions and 25 deletions

View File

@@ -1,11 +1,36 @@
const authHeader = require('./auth-header');
const makeRequest = require('./make-request');
const isHeading = str => /\h\d/.test(str);
const isReservedHeading = (context, str) => {
const reservedHeadings = [
'after-user-code',
'answers',
'before-user-code',
'description',
'fcc-editable-region',
'hints',
'instructions',
'question',
'seed',
'seed-contents',
'solutions',
'text',
'video-solution'
];
const captureGroupStr = `(${reservedHeadings.join('|')})`;
const regex = new RegExp(`--${captureGroupStr}--`);
return !!(context.match(/^Headline/) && str.match(regex));
};
const isCode = str => /^\/pre\/code|\/code$/.test(str);
const shouldHide = (text, context, challengeTitle) => {
if (isHeading(context) || isCode(context)) {
const isTitle = str => /^(tests\s*->\s*\d+\s*)?->\s*title/.test(str);
const shouldHide = (text, context, challengeTitle, crowdinFilePath) => {
if (crowdinFilePath.endsWith('.yml')) {
return !isTitle(context);
}
if (isReservedHeading(context, text) || isCode(context)) {
return true;
}
return text !== challengeTitle && context.includes('id=front-matter');
@@ -13,18 +38,29 @@ const shouldHide = (text, context, challengeTitle) => {
const getStrings = async ({ projectId, fileId }) => {
let headers = { ...authHeader };
let endPoint = `projects/${projectId}/strings?limit=500`;
if (fileId) {
endPoint += `&fileId=${fileId}`;
}
const strings = await makeRequest({ method: 'get', endPoint, headers });
if (strings.data) {
return strings.data;
} else {
const { error, errors } = strings;
console.error(error ? error : errors);
return null;
let done = false;
let offset = 0;
let strings = [];
while (!done) {
let endPoint = `projects/${projectId}/strings?limit=500&offset=${offset}`;
if (fileId) {
endPoint += `&fileId=${fileId}`;
}
const response = await makeRequest({ method: 'get', endPoint, headers });
if (response.data) {
if (response.data.length) {
strings = [...strings, ...response.data];
offset += 500;
} else {
done = true;
return strings;
}
} else {
const { error, errors } = response;
console.error(error ? error : errors);
}
}
return null;
};
const updateString = async ({ projectId, stringId, propsToUpdate }) => {
@@ -69,11 +105,16 @@ const updateFileStrings = async ({ projectId, fileId, challengeTitle }) => {
}
};
const updateFileString = async ({ projectId, string, challengeTitle }) => {
const updateFileString = async ({
projectId,
string,
challengeTitle,
crowdinFilePath
}) => {
const {
data: { id: stringId, text, isHidden, context }
} = string;
const hideString = shouldHide(text, context, challengeTitle);
const hideString = shouldHide(text, context, challengeTitle, crowdinFilePath);
if (!isHidden && hideString) {
await changeHiddenStatus(projectId, stringId, true);
console.log(