mafulong / google_translation

google translation based on electron.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

google-translate-electron

Open Google Translate at Desktop

Based on https://github.com/laissonsilveira/google-translate-electron

To Use

# Clone this repository
git clone git@github.com:mafulong/google_translation.git
# Go into the repository
cd google_translation
# Install dependencies
npm install
# Run the app
npm start

On macOS it is common for applications and their menu bar to stay active until the user quits explicitly with Cmd + Q

  • 外部软件集成。目前有开放接口给外面: http server, 3000端口。即时翻译。
  • popclip集成可通过下面的popclip shellscript安装插件
  • 可以自己导出成mac运行的app后缀程序。
查看主进程的console.log:
tail -f main.log

外部调用直接翻译。
curl -X POST -d "message=Hello, Electron" http://localhost:3000


集成到popclip
# popclip shellscript nested in an applescript 
name: Trans
shell script: curl -X POST -d $POPCLIP_TEXT http://localhost:3000
interpreter: zsh


# popclip shellscript nested in an applescript 
name: Trans2
applescript: do shell script "echo '{popclip text}' > ~/abchh"


生成mac .app 程序。
npm install
electron-packager . --platform=darwin --arch=x64 --out=./dist --overwrite
Or
npm run npm run gen-mac-app

CX

image-20230630104903336

popclip集成, CX

file

Proxy

可以配置如下内容来开启代理,应对google翻译需要vpn的情况。

文件 ~/.google_translation_config.yml

use_proxy: true  # 或者 false,根据需要设置
proxy: socks5://127.0.0.1:7890

Todo

  • mac系统 全局快捷键一键唤醒app并到前台。已支持。默认cmd+e
  • mac系统 选择文字后 全局快捷键一键唤醒app并到前台并进行翻译。已支持: cmd+e会使用剪贴板的文字进行翻译。非剪贴板不搞了,直接popclip已满足使用。
  • alfred集成: 不搞了。cost和直接快捷键唤醒输入相当。

废弃内容 集成alfred

bundleId在package.json里。这个是alfred使用欧陆词典比如eudic://dict//{query}这样协议时使用的。 同时需要告诉mac bundleId对应了哪个app。这个需要改mac系统里的一个plist文件。

mac系统展示bundle Id是多少:

 osascript -e 'id of app "/Users/mafulong/github/google-translate-electron/dist/google-translate-electron-darwin-x64/google-translate-electron.app"'

好像没啥用。注册bundleId com.electron.google-translate-electron。如果存在会自动替换的。不搞alfred了

/usr/libexec/PlistBuddy -c "Add :LSHandlers:0 dict" ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist
/usr/libexec/PlistBuddy -c "Add :LSHandlers:0:LSHandlerURLScheme string google_trans" ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist
/usr/libexec/PlistBuddy -c "Add :LSHandlers:0:LSHandlerRoleAll string com.electron.google-translate-electron" ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist

/usr/libexec/PlistBuddy -c "Save" ~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist

npx用法

因为 electron-packager 不在项目的 node_modules/.bin 目录中。为了解决这个问题,你可以使用 npx 命令来运行 electron-packager,这样它会在项目的本地 node_modules/.bin 目录中查找

npx electron-packager . --platform=darwin --arch=x64 --out=./dist --overwrite

About

google translation based on electron.


Languages

Language:JavaScript 100.0%