Commit 7eec1088 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Make 'global' keyword internationalizable

Change-Id: I326f2f64f03fcc43a85c6f498e22b36da407815c
parent 3e292608
...@@ -156,7 +156,6 @@ Blockly.usePrefixInYail = false; ...@@ -156,7 +156,6 @@ Blockly.usePrefixInYail = false;
+ maybe index variables have prefix "index", or maybe instead they are treated as "param" + maybe index variables have prefix "index", or maybe instead they are treated as "param"
*/ */
Blockly.globalNamePrefix = "global"; // For names introduced by global variable declarations
Blockly.procedureParameterPrefix = "input"; // For names introduced by procedure/function declarations Blockly.procedureParameterPrefix = "input"; // For names introduced by procedure/function declarations
Blockly.handlerParameterPrefix = "input"; // For names introduced by event handlers Blockly.handlerParameterPrefix = "input"; // For names introduced by event handlers
Blockly.localNamePrefix = "local"; // For names introduced by local variable declarations Blockly.localNamePrefix = "local"; // For names introduced by local variable declarations
...@@ -183,14 +182,14 @@ function (prefix) { ...@@ -183,14 +182,14 @@ function (prefix) {
}; };
Blockly.prefixGlobalMenuName = function (name) { Blockly.prefixGlobalMenuName = function (name) {
return Blockly.globalNamePrefix + Blockly.menuSeparator + name; return Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + name;
}; };
// Return a list of (1) prefix (if it exists, "" if not) and (2) unprefixed name // Return a list of (1) prefix (if it exists, "" if not) and (2) unprefixed name
Blockly.unprefixName = function (name) { Blockly.unprefixName = function (name) {
if (name.indexOf(Blockly.globalNamePrefix + Blockly.menuSeparator) == 0) { if (name.indexOf(Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator) == 0) {
// Globals always have prefix, regardless of flags. Handle these specially // Globals always have prefix, regardless of flags. Handle these specially
return [Blockly.globalNamePrefix, name.substring(Blockly.globalNamePrefix.length + Blockly.menuSeparator.length)]; return [Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX, name.substring(Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX.length + Blockly.menuSeparator.length)];
} else if (!Blockly.showPrefixToUser) { } else if (!Blockly.showPrefixToUser) {
return ["", name]; return ["", name];
} else { } else {
......
...@@ -145,7 +145,7 @@ Blockly.Blocks['lexical_variable_get'] = { ...@@ -145,7 +145,7 @@ Blockly.Blocks['lexical_variable_get'] = {
var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR')); var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR'));
var prefix = prefixPair[0]; var prefix = prefixPair[0];
// Only rename lexical (nonglobal) names // Only rename lexical (nonglobal) names
if (prefix !== Blockly.globalNamePrefix) { if (prefix !== Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX) {
var oldName = prefixPair[1]; var oldName = prefixPair[1];
var newName = freeSubstitution.apply(oldName); var newName = freeSubstitution.apply(oldName);
if (newName !== oldName) { if (newName !== oldName) {
...@@ -157,7 +157,7 @@ Blockly.Blocks['lexical_variable_get'] = { ...@@ -157,7 +157,7 @@ Blockly.Blocks['lexical_variable_get'] = {
var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR')); var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR'));
var prefix = prefixPair[0]; var prefix = prefixPair[0];
// Only return lexical (nonglobal) names // Only return lexical (nonglobal) names
if (prefix !== Blockly.globalNamePrefix) { if (prefix !== Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX) {
var oldName = prefixPair[1]; var oldName = prefixPair[1];
return new Blockly.NameSet([oldName]) return new Blockly.NameSet([oldName])
} else { } else {
...@@ -202,7 +202,7 @@ Blockly.Blocks['lexical_variable_set'] = { ...@@ -202,7 +202,7 @@ Blockly.Blocks['lexical_variable_set'] = {
var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR')); var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR'));
var prefix = prefixPair[0]; var prefix = prefixPair[0];
// Only rename lexical (nonglobal) names // Only rename lexical (nonglobal) names
if (prefix !== Blockly.globalNamePrefix) { if (prefix !== Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX) {
var oldName = prefixPair[1]; var oldName = prefixPair[1];
var newName = freeSubstitution.apply(oldName); var newName = freeSubstitution.apply(oldName);
if (newName !== oldName) { if (newName !== oldName) {
...@@ -219,7 +219,7 @@ Blockly.Blocks['lexical_variable_set'] = { ...@@ -219,7 +219,7 @@ Blockly.Blocks['lexical_variable_set'] = {
var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR')); var prefixPair = Blockly.unprefixName(this.getFieldValue('VAR'));
var prefix = prefixPair[0]; var prefix = prefixPair[0];
// Only return lexical (nonglobal) names // Only return lexical (nonglobal) names
if (prefix !== Blockly.globalNamePrefix) { if (prefix !== Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX) {
var oldName = prefixPair[1]; var oldName = prefixPair[1];
result.insert(oldName); result.insert(oldName);
} }
......
...@@ -53,7 +53,6 @@ function start() { ...@@ -53,7 +53,6 @@ function start() {
Blockly.showPrefixToUser = true; Blockly.showPrefixToUser = true;
Blockly.usePrefixInYail = false; Blockly.usePrefixInYail = false;
Blockly.globalNamePrefix = "global"; // For names introduced by global variable declarations
Blockly.procedureParameterPrefix = "input"; // For names introduced by procedure/function declarations Blockly.procedureParameterPrefix = "input"; // For names introduced by procedure/function declarations
Blockly.handlerParameterPrefix = "input"; // For names introduced by event handlers Blockly.handlerParameterPrefix = "input"; // For names introduced by event handlers
Blockly.localNamePrefix = "local"; // For names introduced by local variable declarations Blockly.localNamePrefix = "local"; // For names introduced by local variable declarations
...@@ -79,14 +78,16 @@ function start() { ...@@ -79,14 +78,16 @@ function start() {
}; };
Blockly.prefixGlobalMenuName = function (name) { Blockly.prefixGlobalMenuName = function (name) {
return Blockly.globalNamePrefix + Blockly.menuSeparator + name; return Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + name;
}; };
// Return a list of (1) prefix (if it exists, "" if not) and (2) unprefixed name // Return a list of (1) prefix (if it exists, "" if not) and (2) unprefixed name
Blockly.unprefixName = function (name) { Blockly.unprefixName = function (name) {
if (name.indexOf(Blockly.globalNamePrefix + Blockly.menuSeparator) == 0) { if (name.indexOf(Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator) == 0) {
// Globals always have prefix, regardless of flags. Handle these specially // Globals always have prefix, regardless of flags. Handle these specially
return [Blockly.globalNamePrefix, name.substring(Blockly.globalNamePrefix.length + Blockly.menuSeparator.length)]; return [Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX,
name.substring(Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX.length +
Blockly.menuSeparator.length)];
} else if (!Blockly.showPrefixToUser) { } else if (!Blockly.showPrefixToUser) {
return ["", name]; return ["", name];
} else { } else {
......
...@@ -37,7 +37,7 @@ Blockly.FieldGlobalFlydown.prototype.flyoutCSSClassName = 'blocklyFieldParameter ...@@ -37,7 +37,7 @@ Blockly.FieldGlobalFlydown.prototype.flyoutCSSClassName = 'blocklyFieldParameter
* @return {!Array.<string>} List of two XML elements. * @return {!Array.<string>} List of two XML elements.
**/ **/
Blockly.FieldGlobalFlydown.prototype.flydownBlocksXML_ = function() { Blockly.FieldGlobalFlydown.prototype.flydownBlocksXML_ = function() {
var name = Blockly.globalNamePrefix + " " + this.getText(); // global name for this parameter field. var name = Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + " " + this.getText(); // global name for this parameter field.
var getterSetterXML = var getterSetterXML =
'<xml>' + '<xml>' +
'<block type="lexical_variable_get">' + '<block type="lexical_variable_get">' +
......
...@@ -90,7 +90,7 @@ Blockly.FieldLexicalVariable.prototype.updateMutation = function() { ...@@ -90,7 +90,7 @@ Blockly.FieldLexicalVariable.prototype.updateMutation = function() {
var text = this.getText(); var text = this.getText();
if (this.sourceBlock_ && this.sourceBlock_.getParent()) { if (this.sourceBlock_ && this.sourceBlock_.getParent()) {
this.sourceBlock_.eventparam = undefined; this.sourceBlock_.eventparam = undefined;
if (text.indexOf(Blockly.globalNamePrefix + ' ') === 0) { if (text.indexOf(Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + ' ') === 0) {
this.sourceBlock_.eventparam = null; this.sourceBlock_.eventparam = null;
return; return;
} }
...@@ -459,8 +459,8 @@ Blockly.LexicalVariable.renameGlobal = function (newName) { ...@@ -459,8 +459,8 @@ Blockly.LexicalVariable.renameGlobal = function (newName) {
var renamingFunction = block.renameLexicalVar; var renamingFunction = block.renameLexicalVar;
if (renamingFunction) { if (renamingFunction) {
renamingFunction.call(block, renamingFunction.call(block,
Blockly.globalNamePrefix + Blockly.menuSeparator + oldName, Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + oldName,
Blockly.globalNamePrefix + Blockly.menuSeparator + newName); Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX + Blockly.menuSeparator + newName);
} }
} }
} }
...@@ -906,7 +906,7 @@ Blockly.LexicalVariable.referenceResult = function (block, name, prefix, env) { ...@@ -906,7 +906,7 @@ Blockly.LexicalVariable.referenceResult = function (block, name, prefix, env) {
var referenceName = unprefixedPair[1]; var referenceName = unprefixedPair[1];
var referenceNotInEnv = ((Blockly.usePrefixInYail && (env.indexOf(possiblyPrefixedReferenceName) == -1)) var referenceNotInEnv = ((Blockly.usePrefixInYail && (env.indexOf(possiblyPrefixedReferenceName) == -1))
|| ((!Blockly.usePrefixInYail) && (env.indexOf(referenceName) == -1))) || ((!Blockly.usePrefixInYail) && (env.indexOf(referenceName) == -1)))
if (!(referencePrefix === Blockly.globalNamePrefix)) { if (!(referencePrefix === Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX)) {
if ((referenceName === name) && referenceNotInEnv) { if ((referenceName === name) && referenceNotInEnv) {
// if referenceName refers to name and not some intervening declaration, it's a reference to be renamed: // if referenceName refers to name and not some intervening declaration, it's a reference to be renamed:
blocksToRename.push(block); blocksToRename.push(block);
...@@ -1032,7 +1032,7 @@ Blockly.LexicalVariable.getEventParam = function (block) { ...@@ -1032,7 +1032,7 @@ Blockly.LexicalVariable.getEventParam = function (block) {
// evaluated it. // evaluated it.
var prefixPair = Blockly.unprefixName(block.getFieldValue("VAR")); var prefixPair = Blockly.unprefixName(block.getFieldValue("VAR"));
var prefix = prefixPair[0]; var prefix = prefixPair[0];
if (prefix !== Blockly.globalNamePrefix) { if (prefix !== Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX) {
var name = prefixPair[1]; var name = prefixPair[1];
var child = block; var child = block;
var parent = block.getParent(); var parent = block.getParent();
......
...@@ -90,7 +90,7 @@ Blockly.Yail['getVariableCommandAndName'] = function(name){ ...@@ -90,7 +90,7 @@ Blockly.Yail['getVariableCommandAndName'] = function(name){
var pair = Blockly.unprefixName(name); var pair = Blockly.unprefixName(name);
var prefix = pair[0]; var prefix = pair[0];
var unprefixedName = pair[1]; var unprefixedName = pair[1];
if (prefix === Blockly.globalNamePrefix) { if (prefix === Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX) {
name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + unprefixedName; name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + unprefixedName;
command = Blockly.Yail.YAIL_GET_VARIABLE; command = Blockly.Yail.YAIL_GET_VARIABLE;
} else { } else {
...@@ -106,7 +106,7 @@ Blockly.Yail['setVariableCommandAndName'] = function(name){ ...@@ -106,7 +106,7 @@ Blockly.Yail['setVariableCommandAndName'] = function(name){
var pair = Blockly.unprefixName(name); var pair = Blockly.unprefixName(name);
var prefix = pair[0]; var prefix = pair[0];
var unprefixedName = pair[1]; var unprefixedName = pair[1];
if (prefix === Blockly.globalNamePrefix) { if (prefix === Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX) {
name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + unprefixedName; name = Blockly.Yail.YAIL_GLOBAL_VAR_TAG + unprefixedName;
command = Blockly.Yail.YAIL_SET_VARIABLE; command = Blockly.Yail.YAIL_SET_VARIABLE;
} else { } else {
......
...@@ -941,6 +941,7 @@ Blockly.Msg.en.switch_language_to_english = { ...@@ -941,6 +941,7 @@ Blockly.Msg.en.switch_language_to_english = {
Blockly.Msg.LANG_VARIABLES_GLOBAL_DECLARATION_TO = 'to'; Blockly.Msg.LANG_VARIABLES_GLOBAL_DECLARATION_TO = 'to';
Blockly.Msg.LANG_VARIABLES_GLOBAL_DECLARATION_COLLAPSED_TEXT = 'global'; Blockly.Msg.LANG_VARIABLES_GLOBAL_DECLARATION_COLLAPSED_TEXT = 'global';
Blockly.Msg.LANG_VARIABLES_GLOBAL_DECLARATION_TOOLTIP = 'Creates a global variable and gives it the value of the attached blocks.'; Blockly.Msg.LANG_VARIABLES_GLOBAL_DECLARATION_TOOLTIP = 'Creates a global variable and gives it the value of the attached blocks.';
Blockly.Msg.LANG_VARIABLES_GLOBAL_PREFIX = 'global';
Blockly.Msg.LANG_VARIABLES_GET_HELPURL = '/reference/blocks/variables.html#get'; Blockly.Msg.LANG_VARIABLES_GET_HELPURL = '/reference/blocks/variables.html#get';
Blockly.Msg.LANG_VARIABLES_GET_TITLE_GET = 'get'; Blockly.Msg.LANG_VARIABLES_GET_TITLE_GET = 'get';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment