monaco-editor icon indicating copy to clipboard operation
monaco-editor copied to clipboard

Different languages for the editor

Open MSeifert04 opened this issue 7 years ago • 4 comments

The monaco editor (and vscode) does support multiple languages (like french, german, etc.), however it seems like the bundled editor here is english-only.

Is there anything I've been missing? Or is your monaco-editor or monaco-editor-loader package customizable in a way that allows to bundle multiple languages or a different language?

MSeifert04 avatar Feb 09 '18 15:02 MSeifert04

Hi there – I only really made this as a proof of concept, so I haven't properly looked into how localization works in monaco. Short answer: localization isn't supported in this package (yet…)

Long answer:

  • As far as I can tell, the vs/nls module (submodules/vscode/src/vs/nls.js in this repo) is used for localization throughout the vscode library; the localize() method from this module is used to get the localized version of a string

  • It also looks like the vscode-nls library (submodules/vscode-nls/src/main.ts) is used for localization within some of the extensions (e.g. the CSS language services), however I'm not sure whether the language services support non-English languages.

  • It appears that the vs/nls.js module was written as an AMD plugin, whose load() method would be called automatically with the global AMD config, which can contain a vs/nls setting that determines the language. This doesn't get run in the webpack version, so it seems to default to English.

If you want to get your hands dirty, I'd guess that you can probably build translated versions by adding a vs/nls entry to the webpack resolve.alias setting (defined in webpack/createConfig.js). You could use this to provide a mock version of vs/nls that implements a localize() method which is pre-bound to return strings from the correct language.

I'm not entirely sure how the alternate language strings are generated – I think it's part of the vscode gulp build process (submodules/vscode/build/lib/nls.js) but it looks a bit fiddly. My webpack version uses a totally different build process, so those files won't be generated – however it looks like you might be able to grab pre-built versions of the strings for different languages in the monaco-editor npm package, in dev/vs/editor/editor.main.nls.[lang].js.

If you manage to get localization working, let me know how you did it and I'll try to integrate it into this package!

timkendrick avatar Feb 09 '18 22:02 timkendrick

Thank you for the answer.

I haven't been able to get the translations yet. I'll let you know if I find a way but currently that's not really a priority - it would just be nice to have.

MSeifert04 avatar Feb 13 '18 12:02 MSeifert04

Yep – I plan to get round to this at some point, so I'll keep this issue open.

timkendrick avatar Feb 13 '18 13:02 timkendrick

Hi, anybody managed to get localization working ?

tom-s avatar Oct 27 '18 13:10 tom-s