jslogo icon indicating copy to clipboard operation
jslogo copied to clipboard

Codemirror not highlighting code in locales other than English

Open Danita opened this issue 7 years ago • 4 comments

Hi, I forked this wonderful project in order to add the Spanish translation, and today I stumbled on this. Please excuse any inaccuracies because I'm not completely familiar with the codebase yet.

As I understand the problem arises from the CM logo lexer cm/logo.js having the English keywords hardcoded. Possible solutions that come to my mind:

  • Add a new lexer for each language code. Cons: too much shared code.
  • Attempt to monkeypatch the CodeMirror mode indent() and token() after reading the l10n file to support custom regexes.
  • Best, I think: programmatically generate the lexer according to the selected language and lazy loading it.

Thoughts?

Danita avatar Mar 05 '17 15:03 Danita

We really only need the keywords TRUE, FALSE, ELSE, TO and END, correct? (As an aside, the interpreter doesn't treat TRUE, FALSE and TO as keywords; perhaps it should.)

Another option that comes to mind is to have the mode's lexer have hooks that index.js can interact with, much like the interpreter itself. We could assign a keyword map to the global (window) or another object and the mode's lexer could use that rather than hardcoded regular expressions. That might be simpler.

Otherwise, I agree that programmatically generating the lexer might be easiest. I'd definitely be willing to review patches here. Thank you very much for reporting this and investigating possible options!

inexorabletash avatar Mar 07 '17 04:03 inexorabletash

You're welcome Joshua, I liked your implementation of Logo very much and I'll be collaborating on a time-permitting basis 😄

I agree the hooks approach might be simpler to implement. I'll try this once I finish the Spanish translation.

Danita avatar Mar 07 '17 11:03 Danita

Shouldn't the keywords (like is usually the case with programming languages) always be in English? Regardless of the language used "around" it?

Svish avatar May 01 '17 22:05 Svish

Since Logo is aimed at introductory programming (and kids) it is often localized, even down to the level of keywords. Particularly when the procedure library is localized, the remaining keywords — and there's only a few, listed above — really stand out.

Standardization and portability of the language was never a big concern.

inexorabletash avatar May 01 '17 22:05 inexorabletash