Repository navigation
Description
Python seed comments bypass dictionary validation and translation. translateComments handles js, jsx, and html, but py falls through to the default branch and returns the source unchanged.
freeCodeCamp/tools/challenge-parser/translation-parser/index.js
Lines 3 to 16 in 6ff6dae
| exports.translateComments = (text, lang, dict, codeLang) => { | |
| const knownComments = Object.keys(dict); | |
| const config = { knownComments, dict, lang }; | |
| const input = { text }; | |
| switch (codeLang) { | |
| case 'js': | |
| case 'jsx': | |
| return transMultiline(transInline(input, config), config); | |
| case 'html': | |
| return transScript(transHTML(transCSS(input, config), config), config); | |
| default: | |
| return input; | |
| } | |
| }; |
I reproduced both behaviors from the repository root:
const { translateComments } = require('./tools/challenge-parser/translation-parser');
const dict = { 'Example comment': { spanish: 'Comentario de ejemplo' } };
translateComments('# Example comment', 'spanish', dict, 'py');
// Returns { text: '# Example comment' }, ignoring the translation.
translateComments('# Unregistered comment', 'spanish', {}, 'py');
// Returns the source unchanged without an error.With js and // comments, the same calls translate the registered comment and throw for the unregistered comment.
The ISBN validator lab provides an existing example: none of its 15 seed-comment occurrences are registered in either curriculum/dictionaries/english/comments.json or curriculum/dictionaries/english/comments-to-not-translate.json.
freeCodeCamp/curriculum/challenges/english/blocks/lab-isbn-validator/686b9720ee1d032bd77a480a.md
Lines 529 to 550 in 6ff6dae
| # Calculate the check digit from other digits | |
| if length == 10: | |
| expected_check_digit = calculate_check_digit_10(main_digits_list) | |
| else: | |
| expected_check_digit = calculate_check_digit_13(main_digits_list) | |
| # Check if the given check digit matches with the calculated check digit | |
| if given_check_digit == expected_check_digit: | |
| print('Valid ISBN Code.') | |
| else: | |
| print('Invalid ISBN Code.') | |
| def calculate_check_digit_10(main_digits_list): | |
| # Note: You don't have to fully understand the logic in this function. | |
| digits_sum = 0 | |
| # Multiply each of the first 9 digits by its corresponding weight (10 to 2) and sum up the results | |
| for index, digit in enumerate(main_digits_list): | |
| digits_sum += digit * (10 - index) | |
| # Find the remainder of dividing the sum by 11, then subtract it from 11 | |
| result = 11 - digits_sum % 11 | |
| # The calculation result can range from 1 to 11. | |
| # If the result is 11, use 0. | |
| # If the result is 10, use upper case X. | |
| # Use the value as it is for other numbers. |
Both dictionaries are loaded into the comment map, so the second registry does not account for these comments.
freeCodeCamp/curriculum/src/build-curriculum.ts
Lines 116 to 155 in 6ff6dae
| const COMMENTS_TO_TRANSLATE = JSON.parse( | |
| readFileSync(resolve(dictionariesDir, 'english', 'comments.json'), 'utf8') | |
| ) as Record<string, string>; | |
| const COMMENTS_TO_NOT_TRANSLATE = JSON.parse( | |
| readFileSync( | |
| resolve(dictionariesDir, 'english', 'comments-to-not-translate.json'), | |
| 'utf8' | |
| ) | |
| ) as Record<string, string>; | |
| // map from english comment text to translations | |
| const translatedCommentMap = Object.entries(COMMENTS_TO_TRANSLATE).reduce( | |
| (acc, [id, text]) => { | |
| return { | |
| ...acc, | |
| [text]: getTranslationEntry(dictionaries, { engId: id, text }) | |
| }; | |
| }, | |
| {} as CommentDictionary | |
| ); | |
| // map from english comment text to itself | |
| const untranslatableCommentMap = Object.values( | |
| COMMENTS_TO_NOT_TRANSLATE | |
| ).reduce((acc, text) => { | |
| const englishEntry = languages.reduce( | |
| (acc, lang) => ({ | |
| ...acc, | |
| [lang]: text | |
| }), | |
| {} | |
| ); | |
| return { | |
| ...acc, | |
| [text]: englishEntry | |
| }; | |
| }, {} as CommentDictionary); | |
| const allComments = { ...translatedCommentMap, ...untranslatableCommentMap }; |
Activity
majestic-owl448 commentedon Oct 4, 2026
This also happens for comments in
css,tsandtsxfiles