scratchfoundation / scratch-blocks

Scratch Blocks is a library for building creative computing interfaces.
https://scratch.mit.edu/developers
Apache License 2.0
2.6k stars 1.39k forks source link

Bidirectional text (e.g. Hebrew with quotes around a part), in a category name fails to load #1721

Open chrisgarrity opened 6 years ago

chrisgarrity commented 6 years ago

Alternately, If you first add the translate extension, then switch to Hebrew, the translate blocks category disappears:

hebrew-bug


Moved from LLK/scratch-vm#1390 /cc @ericrosenbaum

Copied from @picklesrus comment This turns out to be a problem related to the characters in the translation of the category label into Hebrew.

Here's text that makes it fail: "message": "תרגום \"גוגל\""

The escaped quotes are confusing the category menu label - everything that comes after it in the toolbox xml definition gets cut off.

I plugged the that message into a category name in the default toolbox in the scratch-blocks playground and it fails similarly. It seems to be a problem with the scratch-blocks toolbox category name handling escaping in RTL. Plugging the same text into labels on blocks works fine though.

rachel-fenichel commented 6 years ago

Here's the code in label fields that forces text to LTR:

  if (this.sourceBlock_.RTL && text) {
    // The SVG is LTR, force text to be RTL.
    if (this.sourceBlock_.editable_ && this.sourceBlock_.type === 'math_number') {
      text = '\u202A' + text + '\u202C';
    } else {
      text = '\u202B' + text + '\u202C';
    }
  }

Applying this fix in toolbox.js probably goes here or here.

The problem has only showed up for category labels, but I imagine it's also a problem for flyout buttons and labels. To fix, looks like we need something similar at or around this line in flyout_button.

This line may also be relevant (where the toolbox creates the XML for a category label inside the flyout).