Skip to content

Commit

Permalink
fix: message types being incorrect (google#6414)
Browse files Browse the repository at this point in the history
* chore: regen msg dts files

* fix: package tasks not packaging msg.d.ts files

* fix: add setLocale to blockly.ts

* chore: format

* chore: move setLocale

* chore: add comment about setLocale not being useful when used with script tags

* chore: format
  • Loading branch information
BeksOmega authored Sep 26, 2022
1 parent 893787b commit 9c81e75
Show file tree
Hide file tree
Showing 128 changed files with 892 additions and 1,336 deletions.
5 changes: 3 additions & 2 deletions core/blockly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ import {MarkerManager} from './marker_manager.js';
import {Menu} from './menu.js';
import {MenuItem} from './menuitem.js';
import {MetricsManager} from './metrics_manager.js';
import {Msg} from './msg.js';
import {Msg, setLocale} from './msg.js';
import {Mutator} from './mutator.js';
import {Names} from './names.js';
import {Options} from './options.js';
Expand Down Expand Up @@ -560,6 +560,7 @@ export const VARIABLE_DYNAMIC_CATEGORY_NAME: string =
*/
export const PROCEDURE_CATEGORY_NAME: string = Procedures.CATEGORY_NAME;


// Context for why we need to monkey-patch in these functions (internal):
// https://docs.google.com/document/d/1MbO0LEA-pAyx1ErGLJnyUqTLrcYTo-5zga9qplnxeXo/edit?usp=sharing&resourcekey=0-5h_32-i-dHwHjf_9KYEVKg

Expand Down Expand Up @@ -720,7 +721,7 @@ export {Menu};
export {MenuItem};
export {MetricsManager};
export {Mutator};
export {Msg};
export {Msg, setLocale};
export {Names};
export {Options};
export {RenderedConnection};
Expand Down
17 changes: 17 additions & 0 deletions core/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,20 @@ goog.declareModuleId('Blockly.Msg');

/** A dictionary of localised messages. */
export const Msg: {[key: string]: string} = Object.create(null);

/**
* Sets the locale (i.e. the localized messages/block-text/etc) to the given
* locale.
*
* This is not useful/necessary when loading from a script tag, because the
* messages are automatically cluged into the Blockly.Msg object. But we provide
* it in both the script-tag and non-script-tag contexts so that the tscompiler
* can properly create our type definition files.
*
* @param locale An object defining the messages for a given language.
*/
export const setLocale = function(locale: {[key: string]: string}) {
Object.keys(locale).forEach(function(k) {
Msg[k] = locale[k];
});
};
2 changes: 1 addition & 1 deletion scripts/gulpfiles/package_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function packageReadme() {
function packageDTS() {
const handwrittenSrcs = [
'typings/*.d.ts',
'typings/msg/msg.d.ts',
'typings/msg/*.d.ts',
];
return gulp.src(handwrittenSrcs, {base: 'typings'})
.pipe(gulp.src(`${TYPINGS_BUILD_DIR}/**/*.d.ts`))
Expand Down
6 changes: 0 additions & 6 deletions scripts/package/browser/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,3 @@
/* eslint-disable */
'use strict';

// Add a helper method to set the Blockly locale.
Blockly.setLocale = function (locale) {
Object.keys(locale).forEach(function (k) {
Blockly.Msg[k] = locale[k];
});
};
6 changes: 0 additions & 6 deletions scripts/package/node/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
/* eslint-disable */
'use strict';

// Add a helper method to set the Blockly locale.
Blockly.setLocale = function (locale) {
Object.keys(locale).forEach(function (k) {
Blockly.Msg[k] = locale[k];
});
};

// Override textToDomDocument and provide Node.js alternatives to DOMParser and
// XMLSerializer.
Expand Down
12 changes: 2 additions & 10 deletions typings/msg/ab.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly ab locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

8 changes: 8 additions & 0 deletions typings/msg/ace.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

export * from './msg';

8 changes: 8 additions & 0 deletions typings/msg/af.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

export * from './msg';

8 changes: 8 additions & 0 deletions typings/msg/am.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/ar.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly ar locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

8 changes: 8 additions & 0 deletions typings/msg/ast.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/az.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly az locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/ba.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly ba locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/bcc.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly bcc locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/be-tarask.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly be-tarask locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/be.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly be locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/bg.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly bg locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/bn.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly bn locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/br.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly br locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/bs.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly bs locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/ca.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly ca locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

8 changes: 8 additions & 0 deletions typings/msg/cdo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/cs.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly cs locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

12 changes: 2 additions & 10 deletions typings/msg/da.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
/**
* @license
* Copyright 2020 Google LLC
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

/**
* @fileoverview Type definitions for the Blockly da locale.
* @author samelh@google.com (Sam El-Husseini)
*/

/// <reference path="msg.d.ts" />

import BlocklyMsg = Blockly.Msg;
export = BlocklyMsg;
export * from './msg';

Loading

0 comments on commit 9c81e75

Please sign in to comment.