@@ -21,17 +21,34 @@ const { metaSchemaValidator } = require('./schema/meta-schema');
21
21
22
22
const access = util . promisify ( fs . access ) ;
23
23
24
- const CHALLENGES_DIR = path . resolve ( __dirname , 'challenges' ) ;
25
- const META_DIR = path . resolve ( CHALLENGES_DIR , '_meta' ) ;
26
- exports . CHALLENGES_DIR = CHALLENGES_DIR ;
24
+ const ENGLISH_CHALLENGES_DIR = path . resolve ( __dirname , 'challenges' ) ;
25
+ const ENGLISH_DICTIONARIES_DIR = path . resolve ( __dirname , 'dictionaries' ) ;
26
+ const META_DIR = path . resolve ( ENGLISH_CHALLENGES_DIR , '_meta' ) ;
27
+
28
+ const CURRICULUM_DIR = path . resolve (
29
+ __dirname ,
30
+ process . env . BUILD_WITH_SUBMODULE === 'true'
31
+ ? 'i18n-curriculum/curriculum'
32
+ : '.'
33
+ ) ;
34
+
35
+ const CHALLENGES_DIR = path . resolve ( CURRICULUM_DIR , 'challenges' ) ;
36
+ const DICTIONARIES_DIR = path . resolve ( CURRICULUM_DIR , 'dictionaries' ) ;
37
+
38
+ exports . ENGLISH_CHALLENGES_DIR = ENGLISH_CHALLENGES_DIR ;
27
39
exports . META_DIR = META_DIR ;
40
+ exports . CHALLENGES_DIR = CHALLENGES_DIR ;
28
41
29
42
const COMMENT_TRANSLATIONS = createCommentMap (
30
- path . resolve ( __dirname , 'dictionaries' )
43
+ DICTIONARIES_DIR ,
44
+ ENGLISH_DICTIONARIES_DIR
31
45
) ;
32
46
33
- function createCommentMap ( dictionariesDir ) {
34
- // get all the languages for which there are dictionaries.
47
+ function createCommentMap ( dictionariesDir , englishDictionariesDir ) {
48
+ // get all the languages for which there are dictionaries. Note: this has to
49
+ // include the english dictionaries since translateCommentsInChallenge treats
50
+ // all languages equally and will simply remove comments if there is no entry
51
+ // in the comment map.
35
52
const languages = fs . readdirSync ( dictionariesDir ) ;
36
53
37
54
// get all their dictionaries
@@ -45,11 +62,15 @@ function createCommentMap(dictionariesDir) {
45
62
46
63
// get the english dicts
47
64
const COMMENTS_TO_TRANSLATE = require (
48
- path . resolve ( dictionariesDir , 'english' , 'comments.json' )
65
+ path . resolve ( englishDictionariesDir , 'english' , 'comments.json' )
49
66
) ;
50
67
51
68
const COMMENTS_TO_NOT_TRANSLATE = require (
52
- path . resolve ( dictionariesDir , 'english' , 'comments-to-not-translate' )
69
+ path . resolve (
70
+ englishDictionariesDir ,
71
+ 'english' ,
72
+ 'comments-to-not-translate.json'
73
+ )
53
74
) ;
54
75
55
76
// map from english comment text to translations
@@ -98,7 +119,11 @@ function getTranslationEntry(dicts, { engId, text }) {
98
119
}
99
120
100
121
function getChallengesDirForLang ( lang ) {
101
- return path . resolve ( CHALLENGES_DIR , `${ lang } ` ) ;
122
+ if ( lang === 'english' ) {
123
+ return path . resolve ( ENGLISH_CHALLENGES_DIR , `${ lang } ` ) ;
124
+ } else {
125
+ return path . resolve ( CHALLENGES_DIR , `${ lang } ` ) ;
126
+ }
102
127
}
103
128
104
129
function getMetaForBlock ( block ) {
@@ -221,7 +246,7 @@ async function buildChallenges({ path: filePath }, curriculum, lang) {
221
246
const isCert = path . extname ( filePath ) === '.yml' ;
222
247
const englishPath = path . resolve (
223
248
__dirname ,
224
- CHALLENGES_DIR ,
249
+ ENGLISH_CHALLENGES_DIR ,
225
250
'english' ,
226
251
filePath
227
252
) ;
@@ -336,7 +361,8 @@ function challengeFilesToPolys(files) {
336
361
337
362
async function assertHasEnglishSource ( filePath , lang , englishPath ) {
338
363
const missingEnglish =
339
- lang !== 'english' && ! ( await hasEnglishSource ( CHALLENGES_DIR , filePath ) ) ;
364
+ lang !== 'english' &&
365
+ ! ( await hasEnglishSource ( ENGLISH_CHALLENGES_DIR , filePath ) ) ;
340
366
if ( missingEnglish )
341
367
throw Error ( `Missing English challenge for
342
368
${ filePath }
0 commit comments