diff --git a/blockly_compressed.js b/blockly_compressed.js index 49efa5655b5..4afd5d7993b 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -1972,7 +1972,7 @@ $.module$exports$Blockly$Procedures.mutatorOpenListener=function(a){if(a.type=== var module$contents$Blockly$Procedures_mutatorChangeListener=function(a){if(a.type===module$exports$Blockly$Events$utils.CREATE||a.type===module$exports$Blockly$Events$utils.DELETE||a.type===module$exports$Blockly$Events$utils.CHANGE)a=module$exports$Blockly$Workspace.Workspace.getById(a.workspaceId),module$contents$Blockly$Procedures_updateMutatorFlyout(a)}; $.module$exports$Blockly$Procedures.getCallers=function(a,b){var c=[];b=b.getAllBlocks(!1);for(var d=0;d} dependencies An array of dependencies to inject. */ -function packageUMD(namespace, dependencies) { +function packageUMD(namespace, dependencies, template = 'umd.template') { return gulp.umd({ dependencies: function () { return dependencies; }, namespace: function () { return namespace; }, exports: function () { return namespace; }, - template: path.join(TEMPLATE_DIR, 'umd.template') + template: path.join(TEMPLATE_DIR, template) }); }; @@ -321,13 +321,10 @@ function packageLocales() { // Remove references to goog.provide and goog.require. return gulp.src(`${BUILD_DIR}/msg/js/*.js`) .pipe(gulp.replace(/goog\.[^\n]+/g, '')) - .pipe(gulp.insert.prepend(` - var Blockly = {};Blockly.Msg={};`)) - .pipe(packageUMD('Blockly.Msg', [{ - name: 'Blockly', - amd: '../core', - cjs: '../core', - }])) + .pipe(packageUMD( + 'Blockly.Msg', + [{name: 'Blockly'}], + 'umd-msg.template')) .pipe(gulp.dest(`${RELEASE_DIR}/msg`)); }; diff --git a/scripts/i18n/create_messages.py b/scripts/i18n/create_messages.py index 70ce61de3e3..ab418a8d6f1 100755 --- a/scripts/i18n/create_messages.py +++ b/scripts/i18n/create_messages.py @@ -41,7 +41,7 @@ def load_constants(filename): for key in constant_defs: value = constant_defs[key] value = value.replace('"', '\\"') - constants_text += u'\nBlockly.Msg["{0}"] = \"{1}\";'.format( + constants_text += u'\nmessages["{0}"] = \"{1}\";'.format( key, value) return constants_text @@ -88,7 +88,7 @@ def main(): os.curdir, args.source_synonym_file)) # synonym_defs is also being sorted to ensure the same order is kept - synonym_text = '\n'.join([u'Blockly.Msg["{0}"] = Blockly.Msg["{1}"];' + synonym_text = '\n'.join([u'messages["{0}"] = messages["{1}"];' .format(key, synonym_defs[key]) for key in sorted(synonym_defs)]) # Read in constants file, which must be output in every language. @@ -123,6 +123,8 @@ def main(): 'use strict'; +const messages = Object.create(null); + """.format(target_lang.replace('-', '.'))) # For each key in the source language file, output the target value # if present; otherwise, output the source language value with a @@ -136,7 +138,7 @@ def main(): value = source_defs[key] comment = ' // untranslated' value = value.replace('"', '\\"') - outfile.write(u'Blockly.Msg["{0}"] = "{1}";{2}\n' + outfile.write(u'messages["{0}"] = "{1}";{2}\n' .format(key, value, comment)) # Announce any keys defined only for target language. diff --git a/scripts/package/templates/umd-msg.template b/scripts/package/templates/umd-msg.template new file mode 100644 index 00000000000..74c8de0bfc4 --- /dev/null +++ b/scripts/package/templates/umd-msg.template @@ -0,0 +1,16 @@ +/* eslint-disable */ +;(function(root, factory) { + if (typeof define === 'function' && define.amd) { // AMD + define(<%= amd %>, factory); + } else if (typeof exports === 'object') { // Node.js + module.exports = factory(); + } else { // Browser + var messages = factory(); + for (var key in messages) { + root.<%= namespace %>[key] = messages[key]; + } + } +}(this, function() { +<%= contents %> +return messages; +}));