Skip to content

Commit b635c4e

Browse files
committed
Add i18n support
1 parent f7a17d5 commit b635c4e

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

src/blocks/mrc_set_python_variable.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const SET_PYTHON_VARIABLE = {
123123
*/
124124
init: function(this: SetPythonVariableBlock): void {
125125
this.appendValueInput('VALUE')
126-
.appendField('set')
126+
.appendField(Blockly.Msg['SET'])
127127
.appendField(createFieldNonEditableText(''), FIELD_MODULE_OR_CLASS_NAME)
128128
.appendField('.');
129129
this.setStyle(MRC_STYLE_VARIABLES);
@@ -133,21 +133,27 @@ const SET_PYTHON_VARIABLE = {
133133
switch (this.mrcVarKind) {
134134
case VariableKind.MODULE: {
135135
const moduleName = this.getFieldValue(FIELD_MODULE_OR_CLASS_NAME);
136-
tooltip = 'Sets the variable ' + moduleName + '.' + varName + '.';
136+
tooltip = Blockly.Msg['SET_MODULE_VARIABLE_TOOLTIP']
137+
.replace('%1', moduleName)
138+
.replace('%2', varName);
137139
break;
138140
}
139141
case VariableKind.CLASS: {
140142
const className = this.getFieldValue(FIELD_MODULE_OR_CLASS_NAME);
141-
tooltip = 'Sets the variable ' + className + '.' + varName + '.';
143+
tooltip = Blockly.Msg['SET_CLASS_VARIABLE_TOOLTIP']
144+
.replace('%1', className)
145+
.replace('%2', varName);
142146
break;
143147
}
144148
case VariableKind.INSTANCE: {
145149
const className = this.getFieldValue(FIELD_MODULE_OR_CLASS_NAME);
146-
tooltip = 'Sets the variable ' + varName + ' for the given ' + className + ' object.';
150+
tooltip = Blockly.Msg['SET_INSTANCE_VARIABLE_TOOLTIP']
151+
.replace('%1', varName)
152+
.replace('%2', className);
147153
break;
148154
}
149155
default:
150-
throw new Error('mrcVarKind must be "module", "class", or "instance".')
156+
throw new Error(Blockly.Msg['VAR_KIND_MUST_BE_MODULE_CLASS_OR_INSTANCE']);
151157
}
152158
const varTooltips = PythonVariableSetterTooltips[this.mrcKey];
153159
if (varTooltips) {
@@ -226,7 +232,7 @@ const SET_PYTHON_VARIABLE = {
226232
} else {
227233
input.appendField(createFieldNonEditableText(''), FIELD_VARIABLE_NAME);
228234
}
229-
input.appendField('to');
235+
input.appendField(Blockly.Msg['TO']);
230236
if (this.mrcVarType) {
231237
input.setCheck(getAllowedTypesForSetCheck(this.mrcVarType));
232238
}
@@ -279,7 +285,7 @@ export const pythonFromBlock = function(
279285
return code;
280286
}
281287
default:
282-
throw new Error('mrcVarKind must be "module", "class", or "instance".')
288+
throw new Error(Blockly.Msg['VAR_KIND_MUST_BE_MODULE_CLASS_OR_INSTANCE']);
283289
}
284290
};
285291

src/blocks/tokens.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ export function customTokens(t: (key: string) => string): typeof Blockly.Msg {
7676
GET_CLASS_VARIABLE_TOOLTIP: t('BLOCKLY.TOOLTIP.GET_CLASS_VARIABLE'),
7777
GET_INSTANCE_VARIABLE_TOOLTIP: t('BLOCKLY.TOOLTIP.GET_INSTANCE_VARIABLE'),
7878
GET_ENUM_VALUE_TOOLTIP: t('BLOCKLY.TOOLTIP.GET_ENUM_VALUE'),
79+
SET: t('BLOCKLY.SET'),
80+
TO: t('BLOCKLY.TO'),
81+
SET_MODULE_VARIABLE_TOOLTIP: t('BLOCKLY.TOOLTIP.SET_MODULE_VARIABLE'),
82+
SET_CLASS_VARIABLE_TOOLTIP: t('BLOCKLY.TOOLTIP.SET_CLASS_VARIABLE'),
83+
SET_INSTANCE_VARIABLE_TOOLTIP: t('BLOCKLY.TOOLTIP.SET_INSTANCE_VARIABLE'),
7984
VAR_KIND_MUST_BE_MODULE_CLASS_OR_INSTANCE: t('BLOCKLY.ERROR.VAR_KIND_MUST_BE_MODULE_CLASS_OR_INSTANCE'),
8085
MECHANISM_NOT_FOUND_WARNING: t('BLOCKLY.WARNING.MECHANISM_NOT_FOUND'),
8186
WARNING_CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT: t('BLOCKLY.WARNING.CALL_COMPONENT_INSTANCE_METHOD_PRIVATE_COMPONENT'),

src/i18n/locales/en/translation.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
"CREATE": "create",
9898
"FIRE": "fire",
9999
"GET": "get",
100+
"SET": "set",
101+
"TO": "to",
100102
"TOOLTIP":{
101103
"EVALUATE_BUT_IGNORE_RESULT": "Executes the connected block and ignores the result. Allows you to call a function and ignore the return value.",
102104
"NONE": "Returns None.",
@@ -120,7 +122,10 @@
120122
"GET_MODULE_VARIABLE": "Gets the variable %1.%2.",
121123
"GET_CLASS_VARIABLE": "Gets the variable %1.%2.",
122124
"GET_INSTANCE_VARIABLE": "Gets the variable %1 for the given %2 object.",
123-
"GET_ENUM_VALUE": "Gets the enum value %1.%2."
125+
"GET_ENUM_VALUE": "Gets the enum value %1.%2.",
126+
"SET_MODULE_VARIABLE": "Sets the variable %1.%2.",
127+
"SET_CLASS_VARIABLE": "Sets the variable %1.%2.",
128+
"SET_INSTANCE_VARIABLE": "Sets the variable %1 for the given %2 object."
124129
},
125130
"CATEGORY":{
126131
"LISTS": "Lists",

src/i18n/locales/es/translation.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
"CREATE": "crear",
9999
"FIRE": "disparar",
100100
"GET": "obtener",
101+
"SET": "establecer",
102+
"TO": "a",
101103
"TOOLTIP": {
102104
"EVALUATE_BUT_IGNORE_RESULT": "Ejecuta el bloque conectado e ignora el resultado. Te permite llamar una función e ignorar el valor de retorno.",
103105
"NONE": "No devuelve ninguno.",
@@ -121,7 +123,10 @@
121123
"GET_MODULE_VARIABLE": "Obtiene la variable %1.%2.",
122124
"GET_CLASS_VARIABLE": "Obtiene la variable %1.%2.",
123125
"GET_INSTANCE_VARIABLE": "Obtiene la variable %1 para el objeto %2 dado.",
124-
"GET_ENUM_VALUE": "Obtiene el valor de enumeración %1.%2."
126+
"GET_ENUM_VALUE": "Obtiene el valor de enumeración %1.%2.",
127+
"SET_MODULE_VARIABLE": "Establece la variable %1.%2.",
128+
"SET_CLASS_VARIABLE": "Establece la variable %1.%2.",
129+
"SET_INSTANCE_VARIABLE": "Establece la variable %1 para el objeto %2 dado."
125130
},
126131
"CATEGORY": {
127132
"LISTS": "Listas",

src/i18n/locales/he/translation.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
"CREATE": "צור",
9898
"FIRE": "הפעל",
9999
"GET": "קבל",
100+
"SET": "הגדר",
101+
"TO": "ל",
100102
"TOOLTIP": {
101103
"EVALUATE_BUT_IGNORE_RESULT": "מבצע את הבלוק המחובר ומתעלם מהתוצאה. מאפשר לקרוא לפונקציה מבלי להשתמש בערך שהיא מחזירה.",
102104
"NONE": "מחזיר כלום.",
@@ -120,7 +122,10 @@
120122
"GET_MODULE_VARIABLE": "מקבל את המשתנה %1.%2.",
121123
"GET_CLASS_VARIABLE": "מקבל את המשתנה %1.%2.",
122124
"GET_INSTANCE_VARIABLE": "מקבל את המשתנה %1 עבור אובייקט %2 נתון.",
123-
"GET_ENUM_VALUE": "מקבל את ערך ההספירה %1.%2."
125+
"GET_ENUM_VALUE": "מקבל את ערך ההספירה %1.%2.",
126+
"SET_MODULE_VARIABLE": "מגדיר את המשתנה %1.%2.",
127+
"SET_CLASS_VARIABLE": "מגדיר את המשתנה %1.%2.",
128+
"SET_INSTANCE_VARIABLE": "מגדיר את המשתנה %1 עבור אובייקט %2 נתון."
124129
},
125130
"CATEGORY": {
126131
"LISTS": "רשימות",

0 commit comments

Comments
 (0)