Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: loading messages from script tags. #6184

Merged
merged 7 commits into from
Jun 13, 2022

Conversation

BeksOmega
Copy link
Collaborator

@BeksOmega BeksOmega commented Jun 1, 2022

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide
  • I ran npm run format and npm run lint

The details

Resolves

Fixes #6123, fixes google/blockly-samples#1066 and fixes google/blockly-samples#1065

Same as #6060, but hopefully this also works for requiring multiple CJS modules.

Proposed Changes

See #6123 (comment)

Also changed the generated, but unwrapped, msg.js files to write to a new messages object, rather than Blockly.Msg to be clearer about what we're doing, and hopefully prevent errors in the future.

Behavior Before Change

Message loading from script tags does not work.

Behavior After Change

Message loading from script tags works.

Reason for Changes

See #6123 (comment)

Test Coverage

  • Playground
  • Playground after changing prepare.js to pull the dist/msg/es.js file instead of msg/messages.js
  • Code demo in core as it currently exists.
  • continuous-toolbox test page
  • continuous-toolbox test page after changing it to import Fr from 'blockly/msg/fr' and Blockly.setLocale(Fr)
  • Mirror demo in samples
  • Plane demo in samples
  • React demo in samples
  • React demo in samples after importing spanish and french, and setting the locale to spanish then french (so french translations are shown)

I couldn't find anything that actually uses CJS modules to be able to test.

Documentation

N/A

Additional Information

Will undraft after testing.

@BeksOmega BeksOmega requested a review from cpcallen June 1, 2022 22:43
@BeksOmega BeksOmega changed the base branch from master to develop June 2, 2022 22:52
@BeksOmega BeksOmega marked this pull request as ready for review June 2, 2022 22:52
@BeksOmega BeksOmega requested a review from a team as a code owner June 2, 2022 22:52
Copy link
Contributor

@cpcallen cpcallen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments as discussed.

@@ -29,12 +29,14 @@ const TEMPLATE_DIR = 'scripts/package/templates';
* @param {string} namespace The export namespace.
* @param {Array<Object>} dependencies An array of dependencies to inject.
*/
function packageUMD(namespace, dependencies) {
function packageUMD(
namespace, dependencies, exportsName = namespace, template = 'umd.template'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted we can probably omit the exportsName parameter and just hardcode return messages' in msg-umd.template.

} else if (typeof exports === 'object') { // Node.js
module.exports = factory();
} else { // Browser
Object.assign(root.<%= namespace %>, factory());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not be compatible with IE11. As discussed: it should be fine to use .setLocale here.

Comment on lines -326 to -329
amd: '../core',
cjs: '../core',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove dependencies because messages don't actually depend on core.

Comment on lines 32 to 34
function packageUMD(
namespace, dependencies, template = 'umd.template'
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting.

Comment on lines 8 to 9
const messages = factory();
for (const key in messages) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted: IE11 doesn't much like const, so use var.

@BeksOmega BeksOmega merged commit 2a7d6b0 into google:develop Jun 13, 2022
BeksOmega added a commit to BeksOmega/blockly that referenced this pull request Jun 13, 2022
* fix: loading messages in the browser

* chore: fix comment

* fix: change unwrapped message files to write to a new object, rather than Blockly.Msg

* fix: fixup exports

* fix: PR comments

* fix: change to use for-in loop

* fix: ES6 compatibility and formatting
@BeksOmega BeksOmega mentioned this pull request Jun 13, 2022
@BeksOmega BeksOmega deleted the fix/umd-msgs branch October 4, 2022 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix language loading problems Mirrored Blockly does not load Plane demo doesn't show translations
2 participants