scratch-blocks 2.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/AGENTS.md +140 -0
  2. package/commitlint.config.js +2 -2
  3. package/dist/main.mjs +1 -2
  4. package/dist/types/msg/scratch_msgs.d.ts.map +1 -1
  5. package/dist/types/src/block_reporting.d.ts.map +1 -1
  6. package/dist/types/src/blocks/colour.d.ts +0 -19
  7. package/dist/types/src/blocks/colour.d.ts.map +1 -1
  8. package/dist/types/src/blocks/control.d.ts +0 -19
  9. package/dist/types/src/blocks/control.d.ts.map +1 -1
  10. package/dist/types/src/blocks/data.d.ts +0 -19
  11. package/dist/types/src/blocks/data.d.ts.map +1 -1
  12. package/dist/types/src/blocks/event.d.ts +0 -19
  13. package/dist/types/src/blocks/event.d.ts.map +1 -1
  14. package/dist/types/src/blocks/looks.d.ts +0 -19
  15. package/dist/types/src/blocks/looks.d.ts.map +1 -1
  16. package/dist/types/src/blocks/math.d.ts +0 -19
  17. package/dist/types/src/blocks/math.d.ts.map +1 -1
  18. package/dist/types/src/blocks/matrix.d.ts +0 -19
  19. package/dist/types/src/blocks/matrix.d.ts.map +1 -1
  20. package/dist/types/src/blocks/motion.d.ts +0 -19
  21. package/dist/types/src/blocks/motion.d.ts.map +1 -1
  22. package/dist/types/src/blocks/note.d.ts +0 -19
  23. package/dist/types/src/blocks/note.d.ts.map +1 -1
  24. package/dist/types/src/blocks/operators.d.ts +0 -19
  25. package/dist/types/src/blocks/operators.d.ts.map +1 -1
  26. package/dist/types/src/blocks/procedures.d.ts +6 -9
  27. package/dist/types/src/blocks/procedures.d.ts.map +1 -1
  28. package/dist/types/src/blocks/sensing.d.ts +0 -19
  29. package/dist/types/src/blocks/sensing.d.ts.map +1 -1
  30. package/dist/types/src/blocks/sound.d.ts +0 -19
  31. package/dist/types/src/blocks/sound.d.ts.map +1 -1
  32. package/dist/types/src/blocks/text.d.ts +0 -19
  33. package/dist/types/src/blocks/text.d.ts.map +1 -1
  34. package/dist/types/src/blocks/vertical_extensions.d.ts +0 -19
  35. package/dist/types/src/blocks/vertical_extensions.d.ts.map +1 -1
  36. package/dist/types/src/checkable_continuous_flyout.d.ts +2 -7
  37. package/dist/types/src/checkable_continuous_flyout.d.ts.map +1 -1
  38. package/dist/types/src/checkbox_bubble.d.ts +13 -12
  39. package/dist/types/src/checkbox_bubble.d.ts.map +1 -1
  40. package/dist/types/src/colours.d.ts.map +1 -1
  41. package/dist/types/src/constants.d.ts +0 -7
  42. package/dist/types/src/constants.d.ts.map +1 -1
  43. package/dist/types/src/context_menu_items.d.ts +0 -5
  44. package/dist/types/src/context_menu_items.d.ts.map +1 -1
  45. package/dist/types/src/data_category.d.ts +2 -4
  46. package/dist/types/src/data_category.d.ts.map +1 -1
  47. package/dist/types/src/events/events_block_comment_base.d.ts +2 -3
  48. package/dist/types/src/events/events_block_comment_base.d.ts.map +1 -1
  49. package/dist/types/src/events/events_block_comment_change.d.ts +0 -5
  50. package/dist/types/src/events/events_block_comment_change.d.ts.map +1 -1
  51. package/dist/types/src/events/events_block_comment_collapse.d.ts +0 -5
  52. package/dist/types/src/events/events_block_comment_collapse.d.ts.map +1 -1
  53. package/dist/types/src/events/events_block_comment_create.d.ts +0 -5
  54. package/dist/types/src/events/events_block_comment_create.d.ts.map +1 -1
  55. package/dist/types/src/events/events_block_comment_delete.d.ts +0 -5
  56. package/dist/types/src/events/events_block_comment_delete.d.ts.map +1 -1
  57. package/dist/types/src/events/events_block_comment_move.d.ts +0 -5
  58. package/dist/types/src/events/events_block_comment_move.d.ts.map +1 -1
  59. package/dist/types/src/events/events_block_comment_resize.d.ts +0 -5
  60. package/dist/types/src/events/events_block_comment_resize.d.ts.map +1 -1
  61. package/dist/types/src/events/events_block_drag_end.d.ts +1 -2
  62. package/dist/types/src/events/events_block_drag_end.d.ts.map +1 -1
  63. package/dist/types/src/events/events_block_drag_outside.d.ts +1 -2
  64. package/dist/types/src/events/events_block_drag_outside.d.ts.map +1 -1
  65. package/dist/types/src/events/events_scratch_variable_create.d.ts +0 -5
  66. package/dist/types/src/events/events_scratch_variable_create.d.ts.map +1 -1
  67. package/dist/types/src/fields/field_colour_slider.d.ts +7 -31
  68. package/dist/types/src/fields/field_colour_slider.d.ts.map +1 -1
  69. package/dist/types/src/fields/field_matrix.d.ts +0 -19
  70. package/dist/types/src/fields/field_matrix.d.ts.map +1 -1
  71. package/dist/types/src/fields/field_note.d.ts +8 -23
  72. package/dist/types/src/fields/field_note.d.ts.map +1 -1
  73. package/dist/types/src/fields/field_textinput_removable.d.ts +2 -4
  74. package/dist/types/src/fields/field_textinput_removable.d.ts.map +1 -1
  75. package/dist/types/src/fields/field_variable_getter.d.ts +0 -19
  76. package/dist/types/src/fields/field_variable_getter.d.ts.map +1 -1
  77. package/dist/types/src/fields/field_vertical_separator.d.ts +0 -19
  78. package/dist/types/src/fields/field_vertical_separator.d.ts.map +1 -1
  79. package/dist/types/src/fields/scratch_field_angle.d.ts +0 -19
  80. package/dist/types/src/fields/scratch_field_angle.d.ts.map +1 -1
  81. package/dist/types/src/fields/scratch_field_dropdown.d.ts +0 -5
  82. package/dist/types/src/fields/scratch_field_dropdown.d.ts.map +1 -1
  83. package/dist/types/src/fields/scratch_field_number.d.ts +0 -19
  84. package/dist/types/src/fields/scratch_field_number.d.ts.map +1 -1
  85. package/dist/types/src/fields/scratch_field_variable.d.ts +5 -8
  86. package/dist/types/src/fields/scratch_field_variable.d.ts.map +1 -1
  87. package/dist/types/src/flyout_checkbox_icon.d.ts +2 -3
  88. package/dist/types/src/flyout_checkbox_icon.d.ts.map +1 -1
  89. package/dist/types/src/glows.d.ts +1 -3
  90. package/dist/types/src/glows.d.ts.map +1 -1
  91. package/dist/types/src/index.d.ts +50 -51
  92. package/dist/types/src/index.d.ts.map +1 -1
  93. package/dist/types/src/procedures.d.ts +6 -8
  94. package/dist/types/src/procedures.d.ts.map +1 -1
  95. package/dist/types/src/recyclable_block_flyout_inflater.d.ts +3 -5
  96. package/dist/types/src/recyclable_block_flyout_inflater.d.ts.map +1 -1
  97. package/dist/types/src/renderer/bowler_hat.d.ts +2 -3
  98. package/dist/types/src/renderer/bowler_hat.d.ts.map +1 -1
  99. package/dist/types/src/renderer/cat/cat_face.d.ts +6 -5
  100. package/dist/types/src/renderer/cat/cat_face.d.ts.map +1 -1
  101. package/dist/types/src/renderer/cat/constants.d.ts +2 -2
  102. package/dist/types/src/renderer/cat/constants.d.ts.map +1 -1
  103. package/dist/types/src/renderer/cat/drawer.d.ts +4 -5
  104. package/dist/types/src/renderer/cat/drawer.d.ts.map +1 -1
  105. package/dist/types/src/renderer/cat/path_object.d.ts +2 -3
  106. package/dist/types/src/renderer/cat/path_object.d.ts.map +1 -1
  107. package/dist/types/src/renderer/cat/render_info.d.ts +3 -4
  108. package/dist/types/src/renderer/cat/render_info.d.ts.map +1 -1
  109. package/dist/types/src/renderer/cat/renderer.d.ts +7 -8
  110. package/dist/types/src/renderer/cat/renderer.d.ts.map +1 -1
  111. package/dist/types/src/renderer/constants.d.ts +41 -0
  112. package/dist/types/src/renderer/constants.d.ts.map +1 -0
  113. package/dist/types/src/renderer/drawer.d.ts +7 -6
  114. package/dist/types/src/renderer/drawer.d.ts.map +1 -1
  115. package/dist/types/src/renderer/path_object.d.ts +1 -3
  116. package/dist/types/src/renderer/path_object.d.ts.map +1 -1
  117. package/dist/types/src/renderer/render_info.d.ts +3 -4
  118. package/dist/types/src/renderer/render_info.d.ts.map +1 -1
  119. package/dist/types/src/renderer/renderer.d.ts +9 -16
  120. package/dist/types/src/renderer/renderer.d.ts.map +1 -1
  121. package/dist/types/src/scratch_block_paster.d.ts +0 -5
  122. package/dist/types/src/scratch_block_paster.d.ts.map +1 -1
  123. package/dist/types/src/scratch_blocks_utils.d.ts +0 -20
  124. package/dist/types/src/scratch_blocks_utils.d.ts.map +1 -1
  125. package/dist/types/src/scratch_comment_bubble.d.ts +3 -6
  126. package/dist/types/src/scratch_comment_bubble.d.ts.map +1 -1
  127. package/dist/types/src/scratch_comment_icon.d.ts +3 -4
  128. package/dist/types/src/scratch_comment_icon.d.ts.map +1 -1
  129. package/dist/types/src/scratch_connection_checker.d.ts +0 -5
  130. package/dist/types/src/scratch_connection_checker.d.ts.map +1 -1
  131. package/dist/types/src/scratch_continuous_category.d.ts +5 -5
  132. package/dist/types/src/scratch_continuous_category.d.ts.map +1 -1
  133. package/dist/types/src/scratch_continuous_toolbox.d.ts +3 -6
  134. package/dist/types/src/scratch_continuous_toolbox.d.ts.map +1 -1
  135. package/dist/types/src/scratch_dragger.d.ts +2 -11
  136. package/dist/types/src/scratch_dragger.d.ts.map +1 -1
  137. package/dist/types/src/scratch_insertion_marker_previewer.d.ts +0 -5
  138. package/dist/types/src/scratch_insertion_marker_previewer.d.ts.map +1 -1
  139. package/dist/types/src/scratch_variable_map.d.ts +0 -5
  140. package/dist/types/src/scratch_variable_map.d.ts.map +1 -1
  141. package/dist/types/src/scratch_variable_model.d.ts +2 -3
  142. package/dist/types/src/scratch_variable_model.d.ts.map +1 -1
  143. package/dist/types/src/scratch_zoom_controls.d.ts +4 -6
  144. package/dist/types/src/scratch_zoom_controls.d.ts.map +1 -1
  145. package/dist/types/src/shadows.d.ts +2 -2
  146. package/dist/types/src/shadows.d.ts.map +1 -1
  147. package/dist/types/src/status_indicator_label.d.ts +4 -6
  148. package/dist/types/src/status_indicator_label.d.ts.map +1 -1
  149. package/dist/types/src/status_indicator_label_flyout_inflater.d.ts +1 -6
  150. package/dist/types/src/status_indicator_label_flyout_inflater.d.ts.map +1 -1
  151. package/dist/types/src/variables.d.ts +4 -8
  152. package/dist/types/src/variables.d.ts.map +1 -1
  153. package/dist/types/src/xml.d.ts +2 -3
  154. package/dist/types/src/xml.d.ts.map +1 -1
  155. package/dist/types/tests/jsunit/block_test.d.ts.map +1 -1
  156. package/dist/types/tests/jsunit/connection_db_test.d.ts +3 -3
  157. package/dist/types/tests/jsunit/connection_db_test.d.ts.map +1 -1
  158. package/dist/types/tests/jsunit/connection_test.d.ts.map +1 -1
  159. package/dist/types/tests/jsunit/event_test.d.ts.map +1 -1
  160. package/dist/types/tests/jsunit/extensions_test.d.ts.map +1 -1
  161. package/dist/types/tests/jsunit/field_number_test.d.ts.map +1 -1
  162. package/dist/types/tests/jsunit/field_test.d.ts.map +1 -1
  163. package/dist/types/tests/jsunit/field_variable_getter_test.d.ts.map +1 -1
  164. package/dist/types/tests/jsunit/field_variable_test.d.ts.map +1 -1
  165. package/dist/types/tests/jsunit/gesture_test.d.ts.map +1 -1
  166. package/dist/types/tests/jsunit/input_test.d.ts +1 -0
  167. package/dist/types/tests/jsunit/input_test.d.ts.map +1 -1
  168. package/dist/types/tests/jsunit/json_test.d.ts.map +1 -1
  169. package/dist/types/tests/jsunit/names_test.d.ts.map +1 -1
  170. package/dist/types/tests/jsunit/procedure_test.d.ts.map +1 -1
  171. package/dist/types/tests/jsunit/scratch_block_comment_test.d.ts.map +1 -1
  172. package/dist/types/tests/jsunit/svg_test.d.ts.map +1 -1
  173. package/dist/types/tests/jsunit/test_utilities.d.ts.map +1 -1
  174. package/dist/types/tests/jsunit/utils_test.d.ts.map +1 -1
  175. package/dist/types/tests/jsunit/variable_map_test.d.ts.map +1 -1
  176. package/dist/types/tests/jsunit/variable_model_test.d.ts.map +1 -1
  177. package/dist/types/tests/jsunit/widget_div_test.d.ts.map +1 -1
  178. package/dist/types/tests/jsunit/workspace_comment_test.d.ts.map +1 -1
  179. package/dist/types/tests/jsunit/workspace_test.d.ts.map +1 -1
  180. package/dist/types/tests/jsunit/workspace_undo_redo_test.d.ts.map +1 -1
  181. package/dist/types/tests/jsunit/xml_test.d.ts.map +1 -1
  182. package/dist/types/tests/workspace_svg/workspace_svg_test.d.ts.map +1 -1
  183. package/eslint.config.mjs +69 -0
  184. package/i18n/create_scratch_msgs.js +44 -45
  185. package/i18n/js_to_json.js +40 -32
  186. package/i18n/json_to_js.js +37 -37
  187. package/i18n/sync_tx_translations.js +64 -65
  188. package/i18n/test_scratch_msgs.js +66 -63
  189. package/msg/js/en.js +289 -287
  190. package/msg/json/en.json +284 -284
  191. package/msg/messages.js +289 -287
  192. package/msg/scratch_msgs.js +22959 -22970
  193. package/package.json +13 -10
  194. package/prettier.config.mjs +3 -0
  195. package/release.config.js +7 -7
  196. package/renovate.json5 +7 -9
  197. package/src/block_reporting.ts +16 -19
  198. package/src/blocks/colour.ts +12 -15
  199. package/src/blocks/control.ts +171 -174
  200. package/src/blocks/data.ts +233 -272
  201. package/src/blocks/event.ts +121 -123
  202. package/src/blocks/looks.ts +165 -167
  203. package/src/blocks/math.ts +44 -46
  204. package/src/blocks/matrix.ts +11 -13
  205. package/src/blocks/motion.ts +151 -153
  206. package/src/blocks/note.ts +11 -13
  207. package/src/blocks/operators.ts +158 -160
  208. package/src/blocks/procedures.ts +421 -511
  209. package/src/blocks/sensing.ts +163 -165
  210. package/src/blocks/sound.ts +58 -60
  211. package/src/blocks/text.ts +10 -12
  212. package/src/blocks/vertical_extensions.ts +86 -102
  213. package/src/checkable_continuous_flyout.ts +25 -42
  214. package/src/checkbox_bubble.ts +83 -100
  215. package/src/colours.ts +35 -37
  216. package/src/constants.ts +22 -29
  217. package/src/context_menu_items.ts +59 -84
  218. package/src/css.ts +3 -4
  219. package/src/data_category.ts +137 -251
  220. package/src/events/events_block_comment_base.ts +23 -30
  221. package/src/events/events_block_comment_change.ts +21 -42
  222. package/src/events/events_block_comment_collapse.ts +27 -36
  223. package/src/events/events_block_comment_create.ts +32 -46
  224. package/src/events/events_block_comment_delete.ts +12 -19
  225. package/src/events/events_block_comment_move.ts +27 -52
  226. package/src/events/events_block_comment_resize.ts +28 -55
  227. package/src/events/events_block_drag_end.ts +16 -26
  228. package/src/events/events_block_drag_outside.ts +12 -22
  229. package/src/events/events_scratch_variable_create.ts +37 -42
  230. package/src/fields/field_colour_slider.ts +186 -216
  231. package/src/fields/field_matrix.ts +202 -270
  232. package/src/fields/field_note.ts +277 -375
  233. package/src/fields/field_textinput_removable.ts +25 -40
  234. package/src/fields/field_variable_getter.ts +26 -31
  235. package/src/fields/field_vertical_separator.ts +19 -24
  236. package/src/fields/scratch_field_angle.ts +151 -187
  237. package/src/fields/scratch_field_dropdown.ts +15 -19
  238. package/src/fields/scratch_field_number.ts +125 -181
  239. package/src/fields/scratch_field_variable.ts +57 -75
  240. package/src/flyout_checkbox_icon.ts +18 -28
  241. package/src/glows.ts +52 -59
  242. package/src/index.ts +119 -133
  243. package/src/procedures.ts +150 -209
  244. package/src/recyclable_block_flyout_inflater.ts +14 -25
  245. package/src/renderer/bowler_hat.ts +6 -8
  246. package/src/renderer/cat/cat_face.ts +98 -99
  247. package/src/renderer/cat/constants.ts +67 -87
  248. package/src/renderer/cat/drawer.ts +21 -27
  249. package/src/renderer/cat/path_object.ts +3 -5
  250. package/src/renderer/cat/render_info.ts +5 -8
  251. package/src/renderer/cat/renderer.ts +12 -16
  252. package/src/renderer/constants.ts +34 -49
  253. package/src/renderer/drawer.ts +35 -51
  254. package/src/renderer/path_object.ts +4 -10
  255. package/src/renderer/render_info.ts +39 -56
  256. package/src/renderer/renderer.ts +17 -30
  257. package/src/scratch_block_paster.ts +12 -20
  258. package/src/scratch_blocks_utils.ts +4 -7
  259. package/src/scratch_comment_bubble.ts +76 -105
  260. package/src/scratch_comment_icon.ts +75 -124
  261. package/src/scratch_connection_checker.ts +7 -17
  262. package/src/scratch_continuous_category.ts +24 -28
  263. package/src/scratch_continuous_toolbox.ts +20 -27
  264. package/src/scratch_dragger.ts +42 -81
  265. package/src/scratch_insertion_marker_previewer.ts +6 -11
  266. package/src/scratch_variable_map.ts +5 -12
  267. package/src/scratch_variable_model.ts +6 -13
  268. package/src/scratch_zoom_controls.ts +101 -156
  269. package/src/shadows.ts +32 -37
  270. package/src/status_indicator_label.ts +54 -67
  271. package/src/status_indicator_label_flyout_inflater.ts +11 -21
  272. package/src/variables.ts +92 -141
  273. package/src/xml.ts +21 -35
  274. package/tsconfig.json +3 -7
  275. package/types/continuous-toolbox.d.ts +1 -1
  276. package/dist/main.mjs.LICENSE.txt +0 -163
@@ -1,52 +1,52 @@
1
- const async = require('async');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const glob = require('glob');
1
+ const async = require('async')
2
+ const fs = require('fs')
3
+ const path = require('path')
4
+ const glob = require('glob')
5
5
 
6
6
  // Globals
7
- const PATH_INPUT = path.resolve(__dirname, '../msg/json/en.json');
7
+ const PATH_INPUT = path.resolve(__dirname, '../msg/json/en.json')
8
8
  // If you want to generate js files for other languages, comment out the line above,
9
9
  // and use the one below instead.
10
10
  // const PATH_INPUT = path.resolve(__dirname, '../msg/json/*.json');
11
- const PATH_OUTPUT = path.resolve(__dirname, '../msg/js');
12
- const CONCURRENCY_LIMIT = 4;
11
+ const PATH_OUTPUT = path.resolve(__dirname, '../msg/js')
12
+ const CONCURRENCY_LIMIT = 4
13
13
 
14
14
  // Processing task
15
15
  const work = function (uri, callback) {
16
- fs.readFile(uri, function (err, body) {
17
- const name = path.parse(uri).name;
18
- if (err) return callback(err);
19
-
20
- // Convert file body into an object (let this throw if invalid JSON)
21
- body = JSON.parse(body);
22
-
23
- // File storage object and preamble
24
- let file = '';
25
- file += '// This file was automatically generated. Do not modify.\n';
26
- file += '\n';
27
- file += '\'use strict\';\n';
28
- file += '\n';
29
- file += `goog.provide(\'Blockly.Msg.${name}\');\n`;
30
- file += 'goog.require(\'Blockly.Msg\');\n';
31
- file += '\n';
32
-
33
- // Iterate over object and build up file
34
- for (let i in body) {
35
- file += `Blockly.Msg["${i}"] = "${body[i].replace(/"/g, '\\"')}";\n`
36
- }
37
-
38
- // Write file to disk
39
- fs.writeFile(`${PATH_OUTPUT}/${name}.js`, file, callback);
40
- });
41
- };
16
+ fs.readFile(uri, function (err, body) {
17
+ const name = path.parse(uri).name
18
+ if (err) return callback(err)
19
+
20
+ // Convert file body into an object (let this throw if invalid JSON)
21
+ body = JSON.parse(body)
22
+
23
+ // File storage object and preamble
24
+ let file = ''
25
+ file += '// This file was automatically generated. Do not modify.\n'
26
+ file += '\n'
27
+ file += "'use strict';\n"
28
+ file += '\n'
29
+ file += `goog.provide(\'Blockly.Msg.${name}\');\n`
30
+ file += "goog.require('Blockly.Msg');\n"
31
+ file += '\n'
32
+
33
+ // Iterate over object and build up file
34
+ for (let i in body) {
35
+ file += `Blockly.Msg["${i}"] = "${body[i].replace(/"/g, '\\"')}";\n`
36
+ }
37
+
38
+ // Write file to disk
39
+ fs.writeFile(`${PATH_OUTPUT}/${name}.js`, file, callback)
40
+ })
41
+ }
42
42
 
43
43
  // Create async processing queue
44
- const q = async.queue(work, CONCURRENCY_LIMIT);
44
+ const q = async.queue(work, CONCURRENCY_LIMIT)
45
45
 
46
46
  // Handle errors
47
47
  q.error = function (err) {
48
- throw new Error(err);
49
- };
48
+ throw new Error(err)
49
+ }
50
50
 
51
51
  // Get all JSON files in input directory and add to queue
52
- q.push(glob.sync(PATH_INPUT));
52
+ q.push(glob.sync(PATH_INPUT))
@@ -8,64 +8,61 @@
8
8
  * token that has developer access.
9
9
  */
10
10
 
11
- const usage = `
11
+ const usage = `
12
12
  Pull supported language translations from Transifex. Usage:
13
13
  node sync_tx_translations.js
14
14
  NOTE: TX_TOKEN environment variable needs to be set with a Transifex API token. See
15
15
  the Localization page on the GUI wiki for information about setting up Transifex.
16
- `;
16
+ `
17
17
  // Fail immediately if the TX_TOKEN is not defined
18
18
  if (!process.env.TX_TOKEN || process.argv.length !== 2) {
19
- process.stdout.write(usage);
20
- process.exit(1);
21
- };
19
+ process.stdout.write(usage)
20
+ process.exit(1)
21
+ }
22
22
 
23
- const fs = require('fs');
24
- const path = require('path');
25
- const assert = require('assert');
26
- const locales = require('scratch-l10n').default;
27
- const {txPull} = require('scratch-l10n/lib/transifex.js');
23
+ const fs = require('fs')
24
+ const path = require('path')
25
+ const assert = require('assert')
26
+ const locales = require('scratch-l10n').default
27
+ const { txPull } = require('scratch-l10n/lib/transifex.js')
28
28
 
29
29
  // Globals
30
- const PATH_OUTPUT = path.resolve(__dirname, '../msg');
30
+ const PATH_OUTPUT = path.resolve(__dirname, '../msg')
31
31
  const PROJECT = 'scratch-editor'
32
- const RESOURCE = 'blocks';
33
- const MODE = 'reviewed';
32
+ const RESOURCE = 'blocks'
33
+ const MODE = 'reviewed'
34
34
 
35
-
36
-
37
- let en = fs.readFileSync(path.resolve(__dirname, '../msg/json/en.json'));
38
- en = JSON.parse(en);
39
- const enKeys = Object.keys(en).sort().toString();
35
+ let en = fs.readFileSync(path.resolve(__dirname, '../msg/json/en.json'))
36
+ en = JSON.parse(en)
37
+ const enKeys = Object.keys(en).sort().toString()
40
38
 
41
39
  // Check that translation is valid:
42
40
  // entry: array [key, translation] corresponding to a single string from <locale>.json
43
41
  // - messages with placeholders have the same number of placeholders
44
42
  // - messages must not have newlines embedded
45
43
  const validateEntry = function (entry) {
46
- const re = /(%\d)/g;
47
- const [key, translation] = entry;
48
- const enMatch = en[key].match(re);
49
- const tMatch = translation.match(re);
50
- const enCount = enMatch ? enMatch.length : 0;
51
- const tCount = tMatch ? tMatch.length : 0;
52
- assert.strictEqual(tCount, enCount, `${key}:${en[key]} - "${translation}" placeholder mismatch`);
53
- if (enCount > 0) {
54
-
55
- assert.notStrictEqual(tMatch, null, `${key} is missing a placeholder: ${translation}`);
56
- assert.strictEqual(
57
- tMatch.sort().toString(),
58
- enMatch.sort().toString(),
59
- `${key} is missing or has duplicate placeholders: ${translation}`
60
- );
61
- }
62
- assert.strictEqual(translation.match(/[\n]/), null, `${key} contains a newline character ${translation}`);
63
- };
44
+ const re = /(%\d)/g
45
+ const [key, translation] = entry
46
+ const enMatch = en[key].match(re)
47
+ const tMatch = translation.match(re)
48
+ const enCount = enMatch ? enMatch.length : 0
49
+ const tCount = tMatch ? tMatch.length : 0
50
+ assert.strictEqual(tCount, enCount, `${key}:${en[key]} - "${translation}" placeholder mismatch`)
51
+ if (enCount > 0) {
52
+ assert.notStrictEqual(tMatch, null, `${key} is missing a placeholder: ${translation}`)
53
+ assert.strictEqual(
54
+ tMatch.sort().toString(),
55
+ enMatch.sort().toString(),
56
+ `${key} is missing or has duplicate placeholders: ${translation}`,
57
+ )
58
+ }
59
+ assert.strictEqual(translation.match(/[\n]/), null, `${key} contains a newline character ${translation}`)
60
+ }
64
61
 
65
62
  const validate = function (json, name) {
66
- assert.strictEqual(Object.keys(json).sort().toString(), enKeys, `${name}: Locale json keys do not match en.json`);
67
- Object.entries(json).forEach(validateEntry);
68
- };
63
+ assert.strictEqual(Object.keys(json).sort().toString(), enKeys, `${name}: Locale json keys do not match en.json`)
64
+ Object.entries(json).forEach(validateEntry)
65
+ }
69
66
 
70
67
  let file = `// This file was automatically generated. Do not modify.
71
68
 
@@ -75,37 +72,39 @@ goog.provide('Blockly.ScratchMsgs.allLocales');
75
72
 
76
73
  goog.require('Blockly.ScratchMsgs');
77
74
 
78
- `;
75
+ `
79
76
 
80
77
  let localeMap = {
81
78
  'aa-dj': 'aa_DJ',
82
79
  'es-419': 'es_419',
83
80
  'pt-br': 'pt_BR',
84
81
  'zh-cn': 'zh_CN',
85
- 'zh-tw': 'zh_TW'
86
- };
82
+ 'zh-tw': 'zh_TW',
83
+ }
87
84
 
88
85
  const getLocaleData = async function (locale) {
89
- let txLocale = localeMap[locale] || locale;
90
- const data = await txPull(PROJECT, RESOURCE, txLocale, MODE);
91
- return {
92
- locale: locale,
93
- translations: data
94
- };
95
- };
96
-
97
- Promise.all(Object.keys(locales).map(getLocaleData)).then(function (values) {
98
- values.forEach(function (translation) {
99
- validate(translation.translations, translation.locale);
100
- file += '\n';
101
- file += `Blockly.ScratchMsgs.locales["${translation.locale}"] =\n`;
102
- file += JSON.stringify(translation.translations, null, 4);
103
- file += ';\n';
104
- });
105
- file += '// End of combined translations\n';
106
- // write combined file
107
- fs.writeFileSync(`${PATH_OUTPUT}/scratch_msgs.js`, file);
108
- }).catch((err) => {
109
- console.error(err);
110
- process.exit(1);
111
- });
86
+ let txLocale = localeMap[locale] || locale
87
+ const data = await txPull(PROJECT, RESOURCE, txLocale, MODE)
88
+ return {
89
+ locale: locale,
90
+ translations: data,
91
+ }
92
+ }
93
+
94
+ Promise.all(Object.keys(locales).map(getLocaleData))
95
+ .then(function (values) {
96
+ values.forEach(function (translation) {
97
+ validate(translation.translations, translation.locale)
98
+ file += '\n'
99
+ file += `Blockly.ScratchMsgs.locales["${translation.locale}"] =\n`
100
+ file += JSON.stringify(translation.translations, null, 4)
101
+ file += ';\n'
102
+ })
103
+ file += '// End of combined translations\n'
104
+ // write combined file
105
+ fs.writeFileSync(`${PATH_OUTPUT}/scratch_msgs.js`, file)
106
+ })
107
+ .catch(err => {
108
+ console.error(err)
109
+ process.exit(1)
110
+ })
@@ -1,87 +1,90 @@
1
- const es = require('event-stream');
2
- const fs = require('fs');
3
- const path = require('path');
4
- const assert = require('assert');
1
+ const es = require('event-stream')
2
+ const fs = require('fs')
3
+ const path = require('path')
4
+ const assert = require('assert')
5
5
 
6
6
  // current locale and keys for the locale
7
- let locale = '';
8
- let keys = [];
7
+ let locale = ''
8
+ let keys = []
9
9
 
10
10
  // current English keys
11
- let en = fs.readFileSync(path.resolve(__dirname, '../msg/json/en.json'));
12
- en = JSON.parse(en);
13
- const enKeys = Object.keys(en);
11
+ let en = fs.readFileSync(path.resolve(__dirname, '../msg/json/en.json'))
12
+ en = JSON.parse(en)
13
+ const enKeys = Object.keys(en)
14
14
 
15
15
  // File paths
16
- const PATH_INPUT = path.resolve(__dirname, '../msg/scratch_msgs.js');
16
+ const PATH_INPUT = path.resolve(__dirname, '../msg/scratch_msgs.js')
17
17
 
18
18
  // Match lines of the scratch_msgs file
19
19
  // Blockly.ScratchMsgs.locales indicates the start of a new locale
20
20
  // ": " marks a "key": "value" pair
21
21
  // Also match the end of the generated file so the last set of keys can be checked
22
22
  const match = function (str) {
23
- if (str.indexOf('Blockly.ScratchMsgs.locales') !== 0) return true;
24
- if (str.indexOf('": "') !== 0) return true;
25
- if (str.indexOf('End of combined translations') !== 0) return true;
26
- return false;
23
+ if (str.indexOf('Blockly.ScratchMsgs.locales') !== 0) return true
24
+ if (str.indexOf('": "') !== 0) return true
25
+ if (str.indexOf('End of combined translations') !== 0) return true
26
+ return false
27
27
  }
28
28
 
29
29
  // Extract key and value from message definition, or locale when it changes
30
30
  const extract = function (str) {
31
- let m = str.match(/locales\["(.+)"\]/);
32
- if (m) {
33
- // locale changed
34
- return m[1];
31
+ let m = str.match(/locales\["(.+)"\]/)
32
+ if (m) {
33
+ // locale changed
34
+ return m[1]
35
+ }
36
+ m = str.match(/"(.*)": "(.*)",?$/)
37
+ if (m) {
38
+ return {
39
+ key: m[1],
40
+ value: m[2],
35
41
  }
36
- m = str.match(/"(.*)": "(.*)",?$/);
37
- if (m) {
38
- return {
39
- key: m[1],
40
- value: m[2]
41
- }
42
- }
43
- // return a string for the end of the file so that validate will check the last set of keys
44
- m = str.match(/^\/\/ End of combined translations$/);
45
- if (m) return 'last';
46
- return null;
47
- };
42
+ }
43
+ // return a string for the end of the file so that validate will check the last set of keys
44
+ m = str.match(/^\/\/ End of combined translations$/)
45
+ if (m) return 'last'
46
+ return null
47
+ }
48
48
 
49
49
  const validateKeys = function () {
50
- // ignore empty keys first time through
51
- if (keys.length === 0) return;
52
- assert.strictEqual(keys.length, Object.keys(en).length, `scratch_msgs-${locale}: number of keys doesn't match`);
53
- keys.map(item => assert(enKeys.includes(item), `scratch_msgs-${locale}: has key ${item} not in en`));
54
- enKeys.map(item => assert(keys.includes(item), `scratch_msgs-${locale}: is missing key ${item}`));
50
+ // ignore empty keys first time through
51
+ if (keys.length === 0) return
52
+ assert.strictEqual(keys.length, Object.keys(en).length, `scratch_msgs-${locale}: number of keys doesn't match`)
53
+ keys.map(item => assert(enKeys.includes(item), `scratch_msgs-${locale}: has key ${item} not in en`))
54
+ enKeys.map(item => assert(keys.includes(item), `scratch_msgs-${locale}: is missing key ${item}`))
55
55
  }
56
56
 
57
57
  // Stream input and push each match to the storage object
58
- const stream = fs.createReadStream(PATH_INPUT);
58
+ const stream = fs.createReadStream(PATH_INPUT)
59
59
  stream
60
- .pipe(es.split('\n'))
61
- .pipe(es.mapSync(function (str) {
62
- if (!match(str)) return;
63
- const result = extract(str);
64
- if (!result) return;
65
- if (typeof result === 'string') {
66
- // locale changed or end of file, validate the current collection of keys
67
- try {
68
- validateKeys();
69
- }
70
- catch (err) {
71
- console.error('Key validation FAILED: %O', err);
72
- process.exit(1);
73
- }
74
- // change locale, and reset keys array
75
- locale = result;
76
- keys = [];
77
- } else {
78
- keys.push(result.key);
60
+ .pipe(es.split('\n'))
61
+ .pipe(
62
+ es.mapSync(function (str) {
63
+ if (!match(str)) return
64
+ const result = extract(str)
65
+ if (!result) return
66
+ if (typeof result === 'string') {
67
+ // locale changed or end of file, validate the current collection of keys
68
+ try {
69
+ validateKeys()
70
+ } catch (err) {
71
+ console.error('Key validation FAILED: %O', err)
72
+ process.exit(1)
79
73
  }
80
- }))
81
- .pipe(es.wait(function (err) {
82
- if (err) {
83
- console.err(err);
84
- process.exit(1);
85
- }
86
- process.exit(0)
87
- }));
74
+ // change locale, and reset keys array
75
+ locale = result
76
+ keys = []
77
+ } else {
78
+ keys.push(result.key)
79
+ }
80
+ }),
81
+ )
82
+ .pipe(
83
+ es.wait(function (err) {
84
+ if (err) {
85
+ console.error(err)
86
+ process.exit(1)
87
+ }
88
+ process.exit(0)
89
+ }),
90
+ )