Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable localization of monaco-editor #10084

Merged
merged 1 commit into from Oct 21, 2021
Merged

Enable localization of monaco-editor #10084

merged 1 commit into from Oct 21, 2021

Conversation

msujew
Copy link
Member

@msujew msujew commented Sep 10, 2021

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 of Record<string, string[]> which is build from the language pack (which uses the form of Record<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 and findWidget). There is a special duplicating logic inside of the script, that needs to be used due to duplicated entries inside of the monaco nls.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, the monaco-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 version 1.60.4, so we don't have to worry about that for quite some time.

How to test

  1. Download a language pack of your choice from the ovsx-registry (version 1.53.2 or newer).
  2. Use the Configure Display Language command to change to that language.
  3. Confirm that the monaco related parts of Theia have been correctly translated:
    • The editor context menu
    • The find widget
    • The Selection main menu entry and its associated commands
  4. You can also test the script using the instructions provided in the script itself.

Review checklist

Reminder for reviewers

@msujew msujew added monaco issues related to monaco localization issues related to localization/internalization/nls labels Sep 10, 2021
Copy link
Member

@vince-fugnitto vince-fugnitto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that I see localizations (french extension-pack) in the following places:

  • editor context-menu items (those contributed by monaco)
  • peek, and find widgets
  • commands contributed by monaco in the quick-commands (F1)

@msujew msujew mentioned this pull request Sep 29, 2021
8 tasks
@msujew msujew merged commit 39d7fde into master Oct 21, 2021
@github-actions github-actions bot added this to the 1.19.0 milestone Oct 21, 2021
@msujew msujew deleted the msujew/monaco-i18n branch October 21, 2021 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
localization issues related to localization/internalization/nls monaco issues related to monaco
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants