electron-userland / electron-spellchecker

Implement spellchecking, correctly
MIT License
237 stars 83 forks source link

Question: How to Change BrowserWindow (Chromium) context menu language #114

Closed WilliamHolmes closed 6 years ago

WilliamHolmes commented 6 years ago

ref: electron 12705

Hi,

Use Case

Our web app allows users to change their preferred language. (Accept-Language Header)

Is it possible to change the default BrowserWindow context menu language?

Currently

image

In this example the user has chosen 'fr', and we use this language for the spellchecker, but the context menu shows in English.

(My Local machine, Mac OS, English)

WilliamHolmes commented 6 years ago

OR another option (for my use case) to remove everything except the spelling suggestions.

WilliamHolmes commented 6 years ago

UPDATE FYI @Slapbox I've managed to find where to change these strings. ContextMenuBuilder.setAlternateStringFormatter eg.

  window.spellCheckHandler = new SpellCheckHandler();
  window.spellCheckHandler.attachToInput();
  window.spellCheckHandler.switchLanguage(lang);
  window.contextMenuBuilder = new ContextMenuBuilder(window.spellCheckHandler, null, true);
  window.contextMenuBuilder.setAlternateStringFormatter({
    copyMail: () => `test_copyMail`,
    copyLinkUrl: () => `test_copyLinkUrl`,
    openLinkUrl: () => `test_openLinkUrl`,
    copyImageUrl: () => `test_copyImageUrl`,
    copyImage: () => `test_copyImage`,
    addToDictionary: () => `test_addToDictionary`,
    lookUpDefinition: ({word}) => `test_lookUpDefinition "${word}"`,
    searchGoogle: () => `test_searchGoogle`,
    cut: () => `test_cut`,
    copy: () => `test_copy`,
    paste: () => `test_paste`,
    inspectElement: () => `test_inspectElement`
  });

image

WilliamHolmes commented 6 years ago

Im closing this issue, as this satisfies my requirements.

Nantris commented 6 years ago

Nice work! Thanks for providing an update for everyone's benefit.