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

Missing i18n for Submenu Labels under "Select" Menu #14995

Closed
Tracked by #14998
likesubject opened this issue Feb 21, 2025 · 7 comments · Fixed by #15016
Closed
Tracked by #14998

Missing i18n for Submenu Labels under "Select" Menu #14995

likesubject opened this issue Feb 21, 2025 · 7 comments · Fixed by #15016
Assignees
Labels
bug bugs found in the application localization issues related to localization/internalization/nls monaco issues related to monaco

Comments

@likesubject
Copy link

Problem Description

Submenu labels under the Select menu (e.g., "All", "Line", "Word") fail to display translated text when using non-English locales. This occurs because the menu labels in monaco-menu.ts were not properly internationalized

Original Code:

In @theia/monaco/src/browser/monaco-menu.ts, the buildMenuAction method did not apply localization handling to the label field. The original code directly used the raw label without passing it through the i18n system.

protected buildMenuAction(commandId: string, item: IMenuItem): MenuAction {
    const title = typeof item.command.title === 'string' ? item.command.title : item.command.title.value;
    const label = this.removeMnemonic(title);
    const order = item.order ? String(item.order) : '';
    return { commandId, order, label };
}

Modified Code:

protected buildMenuAction(commandId: string, item: IMenuItem): MenuAction {
    const title = typeof item.command.title === 'string' ? item.command.title : item.command.title.value;
    let label = this.removeMnemonic(title);
    const order = item.order ? String(item.order) : '';
    label = nls.localizeByDefault(label);
    return { commandId, order, label };
}

Environment:

  • Theia Version: 1.58.3
  • Operating System: Windows 10

Steps to Reproduce

  1. Set the IDE to a non-English locale (e.g., Chinese or French).
  2. Open the Select menu from the top menu bar.
  3. Observe untranslated submenu labels (e.g., "All", "Line").

Expected Behavior: Labels should display translated text according to the configured locale.
Actual Behavior: Labels show raw English text.

Proposed Fix

Added nls.localizeByDefault() to ensure labels are processed for internationalization. Below is the code change:

protected buildMenuAction(commandId: string, item: IMenuItem): MenuAction {
    const title = typeof item.command.title === 'string' ? item.command.title : item.command.title.value;
    let label = this.removeMnemonic(title);
    const order = item.order ? String(item.order) : '';
+    label = nls.localizeByDefault(label);
    return { commandId, order, label };
}
@JonasHelming
Copy link
Contributor

Thank you very much for this report. It seems you already found a solution, would you be interested in contributing this and get the credits?

@msujew
Copy link
Member

msujew commented Feb 21, 2025

Note that this isn't the right approach for localization of Monaco contributed labels. I wasn't aware of this, but it seems like the code for localizing Monaco was removed, see here. This will need to be re-enabled again.

@tsmaeder
Copy link
Contributor

I had a quick look and it seems like putting the code back does not cause any major trouble, but it seems that the Monaco localisation code has change in the mean time. Not all menus are localized when restoring the code "as is".

@tsmaeder
Copy link
Contributor

I particular, a localize2 message has been added.

@msujew
Copy link
Member

msujew commented Feb 21, 2025

I'll take a look at this on Monday, in case you aren't already on it @tsmaeder (I don't work on Fridays)

@tsmaeder tsmaeder mentioned this issue Feb 21, 2025
6 tasks
@tsmaeder
Copy link
Contributor

Adding the following code fixes most of the problems:

import * as MonacoNls from '@theia/monaco-editor-core/esm/vs/nls';
import { nls } from '@theia/core/lib/common/nls';
import { FormatType, Localization } from '@theia/core/lib/common/i18n/localization';

Object.assign(MonacoNls, {
    localize(_key: string, label: string, ...args: FormatType[]): string {
        if (nls.locale) {
            const defaultKey = nls.getDefaultKey(label);
            if (defaultKey) {
                return nls.localize(defaultKey, label, ...args);
            }
        }
        return Localization.format(label, args);
    },
    localize2(_key: string /* | number when built */,
        label: string, ...args: FormatType[]): MonacoNls.ILocalizedString {
        const original = Localization.format(label, args);
        if (nls.locale) {
            const defaultKey = nls.getDefaultKey(label);
            if (defaultKey) {
                return {
                    original,
                    value: nls.localize(defaultKey, label, ...args)
                };
            }
        }
        return {
            original,
            value: original
        };
    }
});

However, there are some problems, in particular the "Paste" action in the editor context menu is not internationalized. I'll let you apply your greater experience with the topic on Monday :-)

@msujew msujew self-assigned this Feb 21, 2025
@msujew msujew added bug bugs found in the application monaco issues related to monaco localization issues related to localization/internalization/nls labels Feb 21, 2025
@msujew
Copy link
Member

msujew commented Feb 24, 2025

I've created #15016 to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs found in the application localization issues related to localization/internalization/nls monaco issues related to monaco
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants