Skip to content

Commit

Permalink
fix: change unwrapped message files to write to a new object, rather …
Browse files Browse the repository at this point in the history
…than Blockly.Msg
  • Loading branch information
BeksOmega committed Jun 2, 2022
1 parent f989a49 commit 0dfb56e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 335 deletions.
5 changes: 1 addition & 4 deletions scripts/gulpfiles/package_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,8 @@ function packageLocales() {
// Remove references to goog.provide and goog.require.
return gulp.src(`${BUILD_DIR}/msg/js/*.js`)
.pipe(gulp.replace(/goog\.[^\n]+/g, ''))
// Create a new object so that (for example)
// require('blockly/msg/es) != require('blockly/msg/fr')
.pipe(gulp.insert.prepend('\nvar Blockly = {};Blockly.Msg={};\n'))
.pipe(packageUMD(
'Blockly.Msg',
'messages',
[{
name: 'Blockly',
amd: '../core',
Expand Down
8 changes: 5 additions & 3 deletions scripts/i18n/create_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
Loading

0 comments on commit 0dfb56e

Please sign in to comment.