Enable localization of monaco-editor #10084
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What it does
Fixes one of the open issues from #9538: Enables the localization of the monaco-editor using vscode language packs.
Monaco is using a quite complicated localization mechanic. We are able to inject our custom translation into monaco using the
loadBundle
function. The callback receives a localization bundle in the form ofRecord<string, string[]>
which is build from the language pack (which uses the form ofRecord<string, Record<string, string>>
). The bulk of the work translating between these formats is done using a script (translate-monaco.js
).The script tries to match the indices of the currently used monaco translation (array based) to the provided language pack (key-value-pair based). This works mostly fine, aside from two special cases (
keybindingLabels
andfindWidget
). There is a special duplicating logic inside of the script, that needs to be used due to duplicated entries inside of the monaconls.js
files.There would be an alternative approach to translating monaco: Update the
@theia/monaco-editor-core
package to natively include the fitting translations. That would alleviate the need for all of this. However, the drawback of that method would be that only selected localizations would be available. For example, themonaco-editor
package on npm does not provide a Turkish translation. Using the Turkish language pack with the current proposed approach translates monaco into Turkish perfectly. We are able to provide arbitrary translations for monaco using language packs this way.The current proposal comes with another drawback: The provided
monaco-nls.json
has to be updated with every monaco update. The scripts should be able to deal with that, but there may be need for small adjustments in the script itself. Another possible drawback is that future language pack versions might not be compatible with the old monaco-editor translations. I couldn't observe any issues with that using a language pack from vscode version1.60.4
, so we don't have to worry about that for quite some time.How to test
1.53.2
or newer).Configure Display Language
command to change to that language.Selection
main menu entry and its associated commandsReview checklist
Reminder for reviewers