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.

Source Source/PopupTranslateSelection.spoon/init.lua line 36

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.
Returns
Examples
Source Source/PopupTranslateSelection.spoon/init.lua line 112
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
Source Source/PopupTranslateSelection.spoon/init.lua line 46
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
Source Source/PopupTranslateSelection.spoon/init.lua line 97