44 * pxt-microbit-ml machine-learning-strings.json. See CodeViewDefaultBlock.tsx
55 * to see where they are used.
66 *
7- * To update all translations, pass 2 arguments:
8- * 1. Path to CreateAI tool translation strings directory.
9- * 2. Path to machine-learning-strings.json translation strings directory.
10- *
11- * To only update CreateAI tool translations, pass path to CreateAI tool
12- * translation strings directory as an argument.
7+ * Pass path to extracted Crowdin ZIP
138 *
149 * Manually run `npm run i18n:compile` after.
1510 *
@@ -20,11 +15,24 @@ const fs = require("fs");
2015const okExitStatus = 0 ;
2116const errExitStatus = 2 ;
2217
23- const languages = [ "ca" , "en" , "es-ES" , "ja" , "ko" , "nl" , "pl" , "pt-br" , "zh-tw" , "lol" ] ;
18+ const languages = [
19+ "ca" ,
20+ "en" ,
21+ "es-ES" ,
22+ "fr" ,
23+ "ja" ,
24+ "ko" ,
25+ "nl" ,
26+ "pl" ,
27+ "pt-BR" ,
28+ "zh-TW" ,
29+ "lol" ,
30+ ] ;
2431const enMessagesToAdd = {
2532 "ml.onStart|block" : {
2633 defaultMessage : "on ML $event start" ,
27- description : "This string should be a Crowdin duplicate of the MakeCode extension block with the same text and use the same translation." ,
34+ description :
35+ "This string should be a Crowdin duplicate of the MakeCode extension block with the same text and use the same translation." ,
2836 } ,
2937} ;
3038
@@ -41,21 +49,23 @@ const getMessagesToAdd = (mlStrings, langMessages) => {
4149 if ( ! langMessages [ k ] ) {
4250 return { ...acc , [ k ] : { ...enMessagesToAdd [ k ] } } ;
4351 }
44- return { ...acc , [ k ] : { ...enMessagesToAdd [ k ] , defaultMessage : acc [ k ] . defaultMessage } } ;
52+ return {
53+ ...acc ,
54+ [ k ] : { ...enMessagesToAdd [ k ] , defaultMessage : acc [ k ] . defaultMessage } ,
55+ } ;
4556 } , { } ) ;
4657} ;
4758const getFileJSONContent = ( filepath ) => JSON . parse ( fs . readFileSync ( filepath ) ) ;
4859
4960const args = process . argv . slice ( 2 ) ;
50- if ( args . length === 0 || args . length > 2 ) {
51- console . log ( `Error: 2 arguments needed.
52- 1. Path to CreateAI tool translation strings directory.
53- 2. Path to machine-learning-strings.json translation strings directory. ` ) ;
61+ if ( args . length !== 1 ) {
62+ console . log ( "Error: Missing argument to extracted Crowdin ZIP" ) ;
5463 process . exit ( errExitStatus ) ;
5564}
5665
57- const [ createAiTranslationsFilepath , mlTranslationsFilepath ] =
58- args . length === 1 ? [ args [ 0 ] , null ] : args ;
66+ const prefix = args [ 0 ] ;
67+ const createAiStringsDir = "new/apps/microbit-createai" ;
68+ const extensionStringsDir = "new/makecode-extensions/pxt-microbit-ml" ;
5969
6070languages . forEach ( ( language ) => {
6171 const lowerLang = language . toLowerCase ( ) ;
@@ -71,18 +81,13 @@ languages.forEach((language) => {
7181 return ;
7282 }
7383
74- const srcLangFilepath = ! createAiTranslationsFilepath
75- ? `lang/ui.${ lowerLang } .json`
76- : `${ createAiTranslationsFilepath } /${ language } /ui.en.json` ;
84+ const srcLangFilepath = `${ prefix } /${ lowerLang } /${ createAiStringsDir } /ui.en.json` ;
7785 const langMessages = getFileJSONContent ( srcLangFilepath ) ;
7886
7987 // Update machine learning strings.
80- let messagesToAdd = { }
81- if ( mlTranslationsFilepath ) {
82- const mlFilepath = `${ mlTranslationsFilepath } /${ language } /machine-learning-strings.json` ;
83- const mlStrings = getFileJSONContent ( mlFilepath ) ;
84- messagesToAdd = getMessagesToAdd ( mlStrings , langMessages ) ;
85- }
88+ const mlFilepath = `${ prefix } /${ lowerLang } /${ extensionStringsDir } /machine-learning-strings.json` ;
89+ const mlStrings = getFileJSONContent ( mlFilepath ) ;
90+ const messagesToAdd = getMessagesToAdd ( mlStrings , langMessages ) ;
8691
8792 fs . writeFileSync (
8893 outputFilepath ,
0 commit comments