feat: restrict translation to audited certs

This commit is contained in:
Oliver Eyton-Williams
2020-02-25 10:20:14 +01:00
committed by Mrugesh Mohapatra
parent 1ec6cf1efd
commit b197f73881
2 changed files with 26 additions and 3 deletions

View File

@ -12,6 +12,7 @@ const {
const { COMMENT_TRANSLATIONS } = require('./comment-dictionary'); const { COMMENT_TRANSLATIONS } = require('./comment-dictionary');
const { dasherize } = require('../utils/slugs'); const { dasherize } = require('../utils/slugs');
const { isAuditedCert } = require('../utils/is-audited');
const challengesDir = path.resolve(__dirname, './challenges'); const challengesDir = path.resolve(__dirname, './challenges');
const metaDir = path.resolve(challengesDir, '_meta'); const metaDir = path.resolve(challengesDir, '_meta');
@ -121,10 +122,17 @@ async function createChallenge(fullPath, maybeMeta) {
meta = require(metaPath); meta = require(metaPath);
} }
const { name: superBlock } = superBlockInfoFromFullPath(fullPath); const { name: superBlock } = superBlockInfoFromFullPath(fullPath);
if (!isAcceptedLanguage(getChallengeLang(fullPath))) const lang = getChallengeLang(fullPath);
throw Error(`${getChallengeLang(fullPath)} is not a accepted language. if (!isAcceptedLanguage(lang))
throw Error(`${lang} is not a accepted language.
Trying to parse ${fullPath}`); Trying to parse ${fullPath}`);
const challenge = await (isEnglishChallenge(fullPath) // assumes superblock names are unique
// while the auditing is ongoing, we default to English for un-audited certs
// once that's complete, we can revert to using isEnglishChallenge(fullPath)
const isEnglish =
isEnglishChallenge(fullPath) || !isAuditedCert(lang, superBlock);
if (isEnglish) fullPath = getEnglishPath(fullPath);
const challenge = await (isEnglish
? parseMarkdown(fullPath) ? parseMarkdown(fullPath)
: parseTranslation( : parseTranslation(
getEnglishPath(fullPath), getEnglishPath(fullPath),

15
utils/is-audited.js Normal file
View File

@ -0,0 +1,15 @@
// this can go once all certs have been audited.
function isAuditedCert(lang, cert) {
if (!lang || !cert)
throw Error('Both arguments must be provided for auditing');
// in order to see the challenges in the client, add the certification that
// contains those challenges to this array:
const auditedCerts = [
'responsive-web-design',
'javascript-algorithms-and-data-structures',
'certificates'
];
return lang === 'english' || auditedCerts.includes(cert);
}
exports.isAuditedCert = isAuditedCert;