Skip to content

Commit

Permalink
chore: move setLocale
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Sep 9, 2022
1 parent 1caeaa5 commit 73d1147
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
15 changes: 2 additions & 13 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,17 +560,6 @@ export const VARIABLE_DYNAMIC_CATEGORY_NAME: string =
*/
export const PROCEDURE_CATEGORY_NAME: string = Procedures.CATEGORY_NAME;

/**
* Sets the locale (i.e. the localized messages/block-text/etc) to the given
* locale.
*
* @param locale An object defining the messages for the given language.
*/
export const setLocale = function(locale: {[key: string]: string}) {
Object.keys(locale).forEach(function(k) {
Blockly.Msg[k] = locale[k];
});
};

// 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 @@ -732,7 +721,7 @@ export {Menu};
export {MenuItem};
export {MetricsManager};
export {Mutator};
export {Msg};
export {Msg, setLocale};
export {Names};
export {Options};
export {RenderedConnection};
Expand Down
12 changes: 12 additions & 0 deletions core/msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ 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.
*
* @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];
});
};
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

0 comments on commit 73d1147

Please sign in to comment.