question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change the language of an existing editor

See original GitHub issue

I am making a directive to help using Monaco Editor in AngularJS 1.X framework. One feature should be updating the language based on the option. But I cannot change the language.

It seems that the type of monacoeditor in my code is ICommonCodeEditor, I tried monacoeditor.updateOptions({ "language": newValues[key] }), it did nothing. I tried monacoeditor.getModel().updateOptions({ "language": newValues[key] }), it did nothing either. I tried also monacoeditor.setModelLanguage(monacoeditor.getModel(), newValues[key]), it gave an error TypeError: monacoeditor.setModelLanguage is not a function.

Note that it is not the problem of the directive, because it works well to change options like lineNumbers.

Could anyone help?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
rebornixcommented, Aug 9, 2017

@SoftTimur from you snippet, it seems you create the editor from string (if you create a model first then my previous comment answers your question IMO). setModelLanguage is a function we exposed in module monaco.editor, it’s not a method of the editor object. So in your case, you can do

var model = monacoeditor.getModel(); // we'll create a model for you if the editor created from string value.
monaco.editor.setModelLanguage(model, "javascript")

Hope this helps you out, if it still doesn’t solve it, I’ll reopen this issue. BTW, you may want to refer monaco.d.ts file for typings reference.

1reaction
rebornixcommented, Aug 9, 2017

image

monaco.editor.setModelLanguage works as expected. Please make sure you are setting language names correctly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the language Office uses in its menus and proofing ...
To configure the editing and proofing language: Within any Office application, select File > Options > Language. The dialog box where you can...
Read more >
How to Change the Language in Microsoft Word
Open an existing or new document in Microsoft Word and select Tools > Language on the menu bar. Pick an editing language, ensure...
Read more >
To change the language of your account (and Editor)
Click the user panel at the top right to open it. Hover over the language at the bottom. Select from the list of...
Read more >
Change your language on the web - Computer - Google Support
Sign in to your Google Account. · On the left, click Personal info. · Under "General preferences for the web," click Language and...
Read more >
How to Change the Proofing Language for Comments in ...
Because … Comments in Word Inherit Proofing Languages. When you use Word's Track Changes to edit someone else's document, the comment tool automatically ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found