Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
Add PopClip Extension (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
quanglam2807 authored Aug 27, 2018
1 parent 38f6b2c commit c4a3d72
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 19 deletions.
20 changes: 20 additions & 0 deletions docs/popclip.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: PopClip Extension
layout: default
---
<section class="section">
<div class="container">
<div class="content has-text-centered">
<p><a href="/">Back to Home</a></p>
<h1 class="title">PopClip Extension</h1>
<p>Open Translatium with the selected text.</p>
<p>
<a href="https://raw.githubusercontent.com/quanglam2807/translatium/master/popclip/Translatium.popclipextz" class="button is-link is-medium">
Download
</a>
</p>
<p><small>The extension requires Translatium v8.6.0 or higher.</small></p>
<p><small>The extension is also available on <a href="https://pilotmoon.com/popclip/extensions/page/Translatium">PilotMoon's website</a> when it is <a href="https://github.com/pilotmoon/PopClip-Extensions/pull/1063">approved by the developer</a>.</small></p>
</div>
</div>
</section>
5 changes: 5 additions & 0 deletions packager.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ builder.build({
productName,
files: [
'!docs/**/*',
'!popclip/**/*',
],
directories: {
buildResources: 'build-resources',
},
protocols: {
name: 'Translatium',
schemes: ['translatium'],
},
afterPack: ({ appOutDir }) =>
new Promise((resolve, reject) => {
console.log('afterPack', appOutDir, process.platform);
Expand Down
1 change: 1 addition & 0 deletions popclip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A pull request has also been created at https://github.com/pilotmoon/PopClip-Extensions/pull/1063.
Binary file added popclip/Translatium.popclipextz
Binary file not shown.
40 changes: 40 additions & 0 deletions popclip/Translatium/Config.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Extension Name</key>
<string>Translatium</string>
<key>Extension Identifier</key>
<string>com.translatium.extension</string>
<key>Extension Description</key>
<string>Open Translatium with the selected text.</string>
<key>Actions</key>
<array>
<dict>
<key>URL</key>
<string>translatium://?text={popclip text}</string>
<key>Image File</key>
<string>translatium.png</string>
<key>Title</key>
<string>Translatium</string>
<key>Regular Expression</key>
<string>(?s)^.{1,1900}$</string>
</dict>
</array>
<key>Apps</key>
<array>
<dict>
<key>Bundle Identifiers</key>
<array>
<string>com.moderntranslator.app</string>
</array>
<key>Check Installed</key>
<true/>
<key>Link</key>
<string>https://translatiumapp.com/</string>
<key>Name</key>
<string>Translatium</string>
</dict>
</array>
</dict>
</plist>
Binary file added popclip/Translatium/translatium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 25 additions & 1 deletion public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const electron = require('electron');
const menubar = require('menubar');
const path = require('path');
const settings = require('electron-settings');
const url = require('url');

const isDev = require('electron-is-dev');

Expand All @@ -19,8 +20,12 @@ const {

const config = require('./config');

// Register protocol
app.setAsDefaultProtocolClient('translatium');

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mb;
let mainWindow;
let menu;

Expand Down Expand Up @@ -163,7 +168,7 @@ function createMenubar() {
}

// Menubar
const mb = menubar({
mb = menubar({
dir: path.resolve(__dirname),
icon: path.resolve(__dirname, 'images', 'iconTemplate.png'),
width: 400,
Expand Down Expand Up @@ -225,3 +230,22 @@ app.on('activate', () => {
createWindow();
}
});

app.on('open-url', (e, urlStr) => {
e.preventDefault();

if (urlStr.startsWith('translatium://')) {
const urlObj = url.parse(urlStr, true);
const text = decodeURIComponent(urlObj.query.text || '');

if (mainWindow) {
mainWindow.send('set-input-lang', 'auto');
mainWindow.send('set-input-text', text);
}

if (mb && mb.window) {
mb.window.send('set-input-lang', 'auto');
mb.window.send('set-input-text', text);
}
}
});
24 changes: 23 additions & 1 deletion src/components/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global ipcRenderer */
import React from 'react';
import PropTypes from 'prop-types';
import { replace, goBack } from 'react-router-redux';
Expand All @@ -15,8 +16,9 @@ import ToggleStar from '@material-ui/icons/Star';
import connectComponent from '../helpers/connect-component';

import { screenResize } from '../state/root/screen/actions';
import { updateImeMode } from '../state/pages/home/actions';
import { updateImeMode, updateInputText } from '../state/pages/home/actions';
import { closeSnackbar } from '../state/root/snackbar/actions';
import { updateInputLang } from '../state/root/settings/actions';

import colorPairs from '../constants/colors';

Expand Down Expand Up @@ -74,6 +76,8 @@ class App extends React.Component {
const {
primaryColorId,
onBackClick,
onUpdateInputText,
onUpdateInputLang,
} = this.props;

this.setAppTitleBar(primaryColorId);
Expand All @@ -92,6 +96,16 @@ class App extends React.Component {
}

window.addEventListener('resize', this.props.onResize);

if (getPlatform() === 'electron') {
ipcRenderer.on('set-input-text', (e, text) => {
onUpdateInputText(text);
});

ipcRenderer.on('set-input-lang', (e, value) => {
onUpdateInputLang(value);
});
}
}

componentWillUpdate(nextProps) {
Expand Down Expand Up @@ -220,6 +234,8 @@ App.propTypes = {
onBottomNavigationActionClick: PropTypes.func.isRequired,
onRequestCloseSnackbar: PropTypes.func.isRequired,
onResize: PropTypes.func.isRequired,
onUpdateInputLang: PropTypes.func.isRequired,
onUpdateInputText: PropTypes.func.isRequired,
primaryColorId: PropTypes.string,
shouldShowBottomNav: PropTypes.bool.isRequired,
snackbarMessage: PropTypes.string,
Expand Down Expand Up @@ -267,6 +283,12 @@ const mapDispatchToProps = dispatch => ({
onBottomNavigationActionClick: pathname => dispatch(replace(pathname)),
onBackClick: () => dispatch(goBack()),
onRequestCloseSnackbar: () => dispatch(closeSnackbar()),
onUpdateInputText: (inputText) => {
dispatch(updateInputText(inputText, 0, 0));
},
onUpdateInputLang: (value) => {
dispatch(updateInputLang(value));
},
});

export default connectComponent(
Expand Down
12 changes: 1 addition & 11 deletions src/components/pages/home/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Windows ipcRenderer */
/* global Windows */
import React from 'react';
import PropTypes from 'prop-types';
import { push } from 'react-router-redux';
Expand Down Expand Up @@ -190,7 +190,6 @@ class Home extends React.Component {
onSwapButtonClick,
onTogglePhrasebookClick,
onWriteButtonClick,
onUpdateInputText,

cameraShortcut,
clearInputShortcut,
Expand All @@ -204,11 +203,6 @@ class Home extends React.Component {
swapLanguagesShortcut,
} = this.props;

if (getPlatform() === 'electron') {
ipcRenderer.on('set-input-text', (e, text) => {
onUpdateInputText(text);
});
}

Mousetrap.bind(openInputLangListShortcut, (e) => {
e.preventDefault();
Expand Down Expand Up @@ -793,7 +787,6 @@ Home.propTypes = {
onTogglePhrasebookClick: PropTypes.func.isRequired,
onTranslateButtonClick: PropTypes.func.isRequired,
onWriteButtonClick: PropTypes.func.isRequired,
onUpdateInputText: PropTypes.func.isRequired,
output: PropTypes.object,
outputLang: PropTypes.string,
preventScreenLock: PropTypes.bool,
Expand Down Expand Up @@ -863,9 +856,6 @@ const mapDispatchToProps = dispatch => ({

dispatch(updateInputText(inputText, e.target.selectionStart, e.target.selectionEnd));
},
onUpdateInputText: (inputText) => {
dispatch(updateInputText(inputText, 0, 0));
},
onClearButtonClick: () => dispatch(updateInputText('')),
onInsertText: text => dispatch(insertInputText(text)),
onListenButtonClick: (toStop, lang, text) => {
Expand Down
8 changes: 8 additions & 0 deletions src/components/pages/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ const Settings = (props) => {
/>
</ListItemSecondaryAction>
</ListItem>
{getPlatform() === 'electron' && (
<ListItem
button
onClick={() => openUri('https://translatiumapp.com/popclip')}
>
<ListItemText primary={strings.popclipExtension} />
</ListItem>
)}
</List>
</Paper>

Expand Down
4 changes: 3 additions & 1 deletion src/strings/de.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,7 @@
"pasteFromClipboard": "Von Zwischenablage einfügen",

"translateClipboardOnShortcut": "Übersetze Zwischenablage mit Tastaturkürzel",
"translateClipboardOnShortcutDesc": "WEnn du Translatium mit einem Tastenkürzel öffnest, wird es automatisch den Inhalt deiner Zwischenablage übersetzen."
"translateClipboardOnShortcutDesc": "WEnn du Translatium mit einem Tastenkürzel öffnest, wird es automatisch den Inhalt deiner Zwischenablage übersetzen.",

"popclipExtension": "PopClip Extension"
}
4 changes: 3 additions & 1 deletion src/strings/en.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,7 @@
"pasteFromClipboard": "Paste from Clipboard",

"translateClipboardOnShortcut": "Translate clipboard on shortcut",
"translateClipboardOnShortcutDesc": "When you open Translatium with a shortcut, it will automatically translate your clipboard contents."
"translateClipboardOnShortcutDesc": "When you open Translatium with a shortcut, it will automatically translate your clipboard contents.",

"popclipExtension": "PopClip Extension"
}
4 changes: 3 additions & 1 deletion src/strings/pl.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,7 @@
"pasteFromClipboard": "Wklej ze schowka",

"translateClipboardOnShortcut": "Przetłumacz schowek skrótem",
"translateClipboardOnShortcutDesc": "Gdy otworzysz Translatium za pomocą skrótu, zawartość schowka zostanie automatycznie przetłumaczona."
"translateClipboardOnShortcutDesc": "Gdy otworzysz Translatium za pomocą skrótu, zawartość schowka zostanie automatycznie przetłumaczona.",

"popclipExtension": "PopClip Extension"
}
4 changes: 3 additions & 1 deletion src/strings/pt_BR.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,7 @@
"pasteFromClipboard": "Colar da Área de Transferência",

"translateClipboardOnShortcut": "Traduzir a área de transferência no atalho",
"translateClipboardOnShortcutDesc": "Quando você abre o Translatium com um atalho, ele irá traduzir automaticamente o conteúdo da área de transferência."
"translateClipboardOnShortcutDesc": "Quando você abre o Translatium com um atalho, ele irá traduzir automaticamente o conteúdo da área de transferência.",

"popclipExtension": "PopClip Extension"
}
4 changes: 3 additions & 1 deletion src/strings/vi.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,7 @@
"pasteFromClipboard": "Dán từ Clipboard",

"translateClipboardOnShortcut": "Dịch clipboard khi dùng phím tắt",
"translateClipboardOnShortcutDesc": "Khi bạn mở Translatium bằng phím tắt, phần mềm sẽ tự động dịch nội dung trong clipboard của bạn."
"translateClipboardOnShortcutDesc": "Khi bạn mở Translatium bằng phím tắt, phần mềm sẽ tự động dịch nội dung trong clipboard của bạn.",

"popclipExtension": "PopClip Extension"
}
4 changes: 3 additions & 1 deletion src/strings/zh-CN.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,7 @@
"pasteFromClipboard": "从剪贴板粘贴",

"translateClipboardOnShortcut": "快捷翻译",
"translateClipboardOnShortcutDesc": "当您使用快捷方式打开 Translatium 时,它将自动翻译您剪贴板的内容。"
"translateClipboardOnShortcutDesc": "当您使用快捷方式打开 Translatium 时,它将自动翻译您剪贴板的内容。",

"popclipExtension": "PopClip Extension"
}

0 comments on commit c4a3d72

Please sign in to comment.