support localization when typing expressions

upd4.1
Jens Mönig 2017-01-19 18:32:57 +01:00
rodzic ce60d740af
commit 55baea09e7
4 zmienionych plików z 21 dodań i 8 usunięć

Wyświetl plik

@ -3310,3 +3310,5 @@ Fixes:
------ ------
* GUI: began new development version * GUI: began new development version
* Blocks: fixed #1630 * Blocks: fixed #1630
* Objects: support localization when typing expressions
* German translation update

Wyświetl plik

@ -185,7 +185,7 @@ SnapTranslator.dict.de = {
'translator_e-mail': 'translator_e-mail':
'jens@moenig.org', // optional 'jens@moenig.org', // optional
'last_changed': 'last_changed':
'2017-01-10', // this, too, will appear in the Translators tab '2017-01-19', // this, too, will appear in the Translators tab
// GUI // GUI
// control bar: // control bar:
@ -1356,6 +1356,10 @@ SnapTranslator.dict.de = {
'e^': 'e^':
'e^', 'e^',
// Boolean expressions keyboard entry
'not':
'nicht',
// delimiters // delimiters
'letter': 'letter':
'Buchstabe', 'Buchstabe',

Wyświetl plik

@ -42,7 +42,7 @@
/*global modules, contains*/ /*global modules, contains*/
modules.locale = '2017-January-13'; modules.locale = '2017-January-19';
// Global stuff // Global stuff
@ -160,7 +160,7 @@ SnapTranslator.dict.de = {
'translator_e-mail': 'translator_e-mail':
'jens@moenig.org', 'jens@moenig.org',
'last_changed': 'last_changed':
'2017-01-10' '2017-01-19'
}; };
SnapTranslator.dict.it = { SnapTranslator.dict.it = {

Wyświetl plik

@ -82,7 +82,7 @@ SpeechBubbleMorph, RingMorph, isNil, FileReader, TableDialogMorph,
BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize, BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/ TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph*/
modules.objects = '2017-January-13'; modules.objects = '2017-January-19';
var SpriteMorph; var SpriteMorph;
var StageMorph; var StageMorph;
@ -2737,7 +2737,8 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
function blockFromAST(ast) { function blockFromAST(ast) {
var block, selectors, monads, alias, key, sel, i, inps, var block, selectors, monads, alias, key, sel, i, inps,
off = 1; off = 1,
reverseDict = {};
selectors = { selectors = {
'+': 'reportSum', '+': 'reportSum',
'-': 'reportDifference', '-': 'reportDifference',
@ -2758,7 +2759,10 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
ceil: 'ceiling', ceil: 'ceiling',
'!' : 'not' '!' : 'not'
}; };
key = alias[ast[0]] || ast[0]; monads.concat(['true', 'false']).forEach(function (word) {
reverseDict[localize(word).toLowerCase()] = word;
});
key = alias[ast[0]] || reverseDict[ast[0].toLowerCase()] || ast[0];
if (contains(monads, key)) { // monadic if (contains(monads, key)) { // monadic
sel = selectors[key]; sel = selectors[key];
if (sel) { // single input if (sel) { // single input
@ -2778,11 +2782,14 @@ SpriteMorph.prototype.reporterize = function (expressionString) {
if (ast[i] instanceof Array) { if (ast[i] instanceof Array) {
block.silentReplaceInput(inps[i - off], blockFromAST(ast[i])); block.silentReplaceInput(inps[i - off], blockFromAST(ast[i]));
} else if (isString(ast[i])) { } else if (isString(ast[i])) {
if (contains(['true', 'false'], ast[i])) { if (contains(
['true', 'false'], reverseDict[ast[i]] || ast[i])
) {
block.silentReplaceInput( block.silentReplaceInput(
inps[i - off], inps[i - off],
SpriteMorph.prototype.blockForSelector( SpriteMorph.prototype.blockForSelector(
ast[i] === 'true' ? 'reportTrue' : 'reportFalse' (reverseDict[ast[i]] || ast[i]) === 'true' ?
'reportTrue' : 'reportFalse'
) )
); );
} else if (ast[i] !== '_') { } else if (ast[i] !== '_') {