docs » PopupTranslateSelection

Show a popup window with the translation of the currently selected (or other) text

Supported language codes are listed at https://cloud.google.com/translate/docs/languages

Download: https://github.com/Hammerspoon/Spoons/raw/master/Spoons/PopupTranslateSelection.spoon.zip

API Overview

API Documentation

Variables

logger
Signature PopupTranslateSelection.logger
Type Variable
Description

Logger object used within the Spoon. Can be accessed to set the default log level for the messages coming from the Spoon.

Methods

bindHotkeys
Signature PopupTranslateSelection:bindHotkeys(mapping)
Type Method
Description

Binds hotkeys for PopupTranslateSelection

Parameters:

  • mapping - A table containing hotkey modifier/key details for the following items:
    • translate - translate the selected text without specifying source/destination languages (source defaults to auto-detect, destination defaults to your last choice or to English)
    • translate_to_<lang> - translate the selected text to the given destination language. Source language will be auto-detected.
    • translate_from_<lang> - translate the selected text from the given destination language. Destination language will default to your last choice, or to English.
    • translate_<from>_<to> - translate the selected text between the given languages.

Sample value for mapping:

 {
    translate_to_en = { { "ctrl", "alt", "cmd" }, "e" },
    translate_to_de = { { "ctrl", "alt", "cmd" }, "d" },
    translate_to_es = { { "ctrl", "alt", "cmd" }, "s" },
    translate_de_en = { { "shift", "ctrl", "alt", "cmd" }, "e" },
    translate_en_de = { { "shift", "ctrl", "alt", "cmd" }, "d" },
 }
translatePopup
Signature PopupTranslateSelection:translatePopup(text, to, from)
Type Method
Description

Display a translation popup with the translation of the given text between the specified languages

Parameters:

  • text - string containing the text to translate
  • to - two-letter code for destination language. If nil, Google Translate will use your most recent selection, or default to English
  • from - two-letter code for source language. If nil, Google Translate will try to auto-detect it

Returns:

  • The PopupTranslateSelection object
translateSelectionPopup
Signature PopupTranslateSelection:translateSelectionPopup(to, from)
Type Method
Description

Get the current selected text in the frontmost window and display a translation popup with the translation between the specified languages

Parameters:

  • to - two-letter code for destination language. If nil, Google Translate will use your most recent selection, or default to English
  • from - two-letter code for source language. If nil, Google Translate will try to auto-detect it

Returns:

  • The PopupTranslateSelection object