Skip to content
This repository was archived by the owner on Aug 16, 2024. It is now read-only.

Commit bf8dbd7

Browse files
authored
Merge pull request #1 from geekdada/dev
2 parents e64a100 + 1a5048c commit bf8dbd7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3086
-1187
lines changed

.babelrc

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
{
22
"presets": [
3-
"@babel/preset-typescript",
4-
"react-app"
5-
],
6-
"plugins": [
7-
"babel-plugin-transform-inline-environment-variables",
8-
"babel-plugin-macros",
93
[
10-
"@emotion/babel-plugin-jsx-pragmatic",
4+
"@babel/preset-env",
115
{
12-
"export": "jsx",
13-
"import": "__cssprop",
14-
"module": "@emotion/react"
6+
"useBuiltIns": "entry",
7+
"corejs": "3.8.2"
158
}
169
],
10+
"@babel/preset-typescript",
1711
[
18-
"@babel/plugin-transform-react-jsx",
19-
{
20-
"pragma": "__cssprop",
21-
"pragmaFrag": "React.Fragment"
22-
}
23-
],
12+
"@babel/preset-react",
13+
{ "runtime": "automatic", "importSource": "@emotion/react" }
14+
]
15+
],
16+
"plugins": [
17+
"@babel/plugin-proposal-class-properties",
18+
"babel-plugin-transform-inline-environment-variables",
19+
"babel-plugin-macros",
20+
["@emotion/babel-plugin", {
21+
"sourceMap": true,
22+
"autoLabel": "dev-only",
23+
"labelFormat": "[local]",
24+
"cssPropOptimization": true
25+
}],
2426
"react-hot-loader/babel"
2527
]
2628
}

.browserslistrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
last 10 Chrome versions

CHANGELOG.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,63 @@
1+
# [0.2.0-5](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-4...v0.2.0-5) (2021-01-22)
2+
3+
4+
### Bug Fixes
5+
6+
* use chinese ([b3b6188](https://github.com/geekdada/a-translator-chrome-extension/commit/b3b61880af68cae845f4c83f12f23c503b49f3b2))
7+
8+
9+
### Features
10+
11+
* add config for hover button ([477de29](https://github.com/geekdada/a-translator-chrome-extension/commit/477de29b86033267db3acb95f042bdbbc1425786))
12+
* add context menus ([ccf87a5](https://github.com/geekdada/a-translator-chrome-extension/commit/ccf87a512664d45c236e0017ccd613ef39d8352e))
13+
* keyboard shortcuts ([c26cf83](https://github.com/geekdada/a-translator-chrome-extension/commit/c26cf83fc92225367cf676e736e773d66f7ed075))
14+
15+
16+
17+
# [0.2.0-4](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-3...v0.2.0-4) (2021-01-21)
18+
19+
20+
### Features
21+
22+
* ocr text for translating ([72b58ed](https://github.com/geekdada/a-translator-chrome-extension/commit/72b58ede93a68032d2b4979e46ae32f35803a9ea))
23+
* turn off ocr tool when the selection is too small ([0e13070](https://github.com/geekdada/a-translator-chrome-extension/commit/0e130708c7c87d1e3e6929509e65abbccff3db8b))
24+
25+
26+
27+
# [0.2.0-3](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-2...v0.2.0-3) (2021-01-20)
28+
29+
30+
### Features
31+
32+
* change target language directly in webpage ([fdb574b](https://github.com/geekdada/a-translator-chrome-extension/commit/fdb574b8210ce6914f64f2a8cfecdde13cdf7ad6))
33+
* retry button ([2b287d3](https://github.com/geekdada/a-translator-chrome-extension/commit/2b287d3fec67c01f25a8a8d7b57c3c0e02962b29))
34+
35+
36+
37+
# [0.2.0-2](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-1...v0.2.0-2) (2021-01-18)
38+
39+
40+
### Bug Fixes
41+
42+
* conflict with emotion 10 application ([699948e](https://github.com/geekdada/a-translator-chrome-extension/commit/699948e1c1f93f43b4e939b4b4652213d1973423))
43+
* style typo ([4e46590](https://github.com/geekdada/a-translator-chrome-extension/commit/4e4659034f871b25ed7a64d24147eec04c542b6e))
44+
45+
46+
47+
# [0.2.0-1](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.2.0-0...v0.2.0-1) (2021-01-18)
48+
49+
50+
51+
# [0.2.0-0](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.6...v0.2.0-0) (2021-01-17)
52+
53+
54+
### Features
55+
56+
* add polyfill for old browsers ([0e38a77](https://github.com/geekdada/a-translator-chrome-extension/commit/0e38a77ea2fe224ae5086d2930ce9d17cc89530a))
57+
* optimize string selection ([7ea8ac7](https://github.com/geekdada/a-translator-chrome-extension/commit/7ea8ac71fb88146e46b6608bc5eeacae659762ac))
58+
59+
60+
161
## [0.1.6](https://github.com/geekdada/a-translator-chrome-extension/compare/v0.1.5...v0.1.6) (2021-01-10)
262

363

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "a-translator-chrome-extension",
3-
"version": "0.1.6",
3+
"version": "0.2.0-5",
44
"description": "A Chrome extension for A Translator",
55
"license": "MIT",
66
"repository": {
@@ -14,27 +14,28 @@
1414
"prettier": "prettier --write '**/*.{js,jsx,ts,tsx,css,html}'",
1515
"lint": "eslint --ext .ts,.tsx,.js,.jsx",
1616
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
17+
"pub": "np --no-publish --no-release-draft",
1718
"version": "npm run changelog && git add ."
1819
},
1920
"dependencies": {
2021
"@babel/core": "^7.12.10",
2122
"@babel/plugin-proposal-class-properties": "^7.12.1",
22-
"@babel/plugin-transform-react-jsx": "^7.12.12",
23-
"@babel/preset-env": "^7.12.10",
23+
"@babel/preset-env": "^7.12.11",
2424
"@babel/preset-react": "^7.12.10",
2525
"@babel/preset-typescript": "^7.12.7",
2626
"@commitlint/cli": "^11.0.0",
2727
"@commitlint/config-angular": "^11.0.0",
2828
"@emotion/babel-plugin": "^11.1.2",
29-
"@emotion/babel-plugin-jsx-pragmatic": "^0.1.5",
29+
"@emotion/cache": "^11.1.3",
3030
"@emotion/css": "^11.1.3",
3131
"@emotion/react": "^11.1.4",
3232
"@emotion/server": "^11.0.0",
3333
"@emotion/styled": "^11.0.0",
3434
"@hot-loader/react-dom": "^17.0.1",
3535
"@material-ui/core": "^4.11.2",
3636
"@tailwindcss/forms": "^0.2.1",
37-
"@types/chrome": "0.0.127",
37+
"@types/chrome": "0.0.128",
38+
"@types/crypto-js": "^4.0.1",
3839
"@types/fs-extra": "^9.0.6",
3940
"@types/lodash-es": "^4.17.4",
4041
"@types/node": "^14",
@@ -43,6 +44,7 @@
4344
"@types/react": "^17.0.0",
4445
"@types/react-collapse": "^5.0.0",
4546
"@types/react-dom": "^17.0.0",
47+
"@types/react-resizable": "^1.7.2",
4648
"@types/uuid": "^8.3.0",
4749
"@typescript-eslint/eslint-plugin": "^4.5.0",
4850
"@typescript-eslint/parser": "^4.5.0",
@@ -52,14 +54,14 @@
5254
"babel-loader": "^8.2.2",
5355
"babel-plugin-macros": "^3.0.1",
5456
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
55-
"babel-preset-react-app": "^10.0.0",
5657
"chrome-call": "^4.0.1",
5758
"clean-webpack-plugin": "^3.0.0",
58-
"clsx": "^1.1.1",
5959
"connect.io": "^3.1.3",
6060
"conventional-changelog-cli": "^2.1.1",
6161
"copy-webpack-plugin": "^6.4.0",
62+
"core-js": "3",
6263
"cross-env": "^7.0.3",
64+
"crypto-js": "^4.0.0",
6365
"css-loader": "^5.0.1",
6466
"dotenv": "^8.2.0",
6567
"eslint": "^7.16.0",
@@ -76,25 +78,29 @@
7678
"mini-css-extract-plugin": "^1.3.3",
7779
"node-sass": "^5.0.0",
7880
"notistack": "^1.0.3",
81+
"np": "^7.2.0",
7982
"npm-run-all": "^4.1.5",
8083
"pino": "^6.9.0",
8184
"postcss": "^8.2.2",
8285
"postcss-import": "^14.0.0",
8386
"postcss-loader": "^4.1.0",
8487
"prettier": "^2.2.1",
8588
"process": "^0.11.10",
89+
"query-string": "^6.13.8",
8690
"rangy": "^1.3.0",
8791
"react": "^17.0.1",
8892
"react-clipboard.js": "^2.0.16",
8993
"react-collapse": "^5.1.0",
9094
"react-dom": "^17.0.1",
9195
"react-draggable": "^4.4.3",
9296
"react-hot-loader": "^4.13.0",
97+
"react-resizable": "^1.11.0",
9398
"react-scroll-to-bottom": "^4.1.0",
9499
"sass-loader": "^10.1.0",
95100
"scrollparent": "^2.0.1",
101+
"semver": "^7.3.4",
96102
"smoothscroll-polyfill": "^0.4.4",
97-
"source-map-loader": "^1.1.3",
103+
"source-map-loader": "^2.0.0",
98104
"style-loader": "^2.0.0",
99105
"tailwindcss": "^2.0.2",
100106
"terser-webpack-plugin": "^5.0.3",

src/common/api.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import axios from 'axios'
2+
import qs from 'query-string'
23

34
import { APIRegions, TranslateResult } from './types'
45

@@ -26,13 +27,24 @@ class Client {
2627
}
2728

2829
async translate(text: string, targetLang: string): Promise<TranslateResult> {
29-
const form = new FormData()
30-
31-
form.append('auth_key', this.apiToken)
32-
form.append('target_lang', targetLang)
33-
form.append('text', text)
34-
35-
return this.axios.post('/v2/translate', form).then((res) => res.data)
30+
return this.axios
31+
.post(
32+
'/v2/translate',
33+
qs.stringify({
34+
auth_key: this.apiToken,
35+
target_lang: targetLang,
36+
split_sentences: '1',
37+
preserve_formatting: '0',
38+
text: text,
39+
}),
40+
{
41+
headers: {
42+
'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
43+
},
44+
responseType: 'json',
45+
},
46+
)
47+
.then((res) => res.data)
3648
}
3749

3850
private getAPI(): string {

src/common/constant.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const supportedLanguages = {
2+
ZH: '中文',
3+
'EN-US': 'English (American)',
4+
'EN-GB': 'English (British)',
5+
JA: '日本語',
6+
DE: 'German',
7+
FR: 'French',
8+
ES: 'Spanish',
9+
'PT-PT': 'Portuguese',
10+
'PT-BR': 'Portuguese (Brazilian)',
11+
IT: 'Italian',
12+
NL: 'Dutch',
13+
PL: 'Polish',
14+
RU: 'Russian',
15+
}

src/common/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const logger = pino({
1616
}
1717

1818
const label = pino.levels.labels[level]
19-
const logs: any[] = [`[ATE] [${label.toUpperCase()}] ${msg}`]
19+
const logs: any[] = [`[ATE] [${label.toUpperCase()}] ${msg || ''}`]
2020
const method = getMethod(level)
2121
const extra = omit(o, ['msg', 'level', 'time', 'err'])
2222

src/common/rangy.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @ts-ignore
2+
import * as rangy from 'rangy'
3+
// @ts-ignore
4+
import 'rangy/lib/rangy-classapplier'
5+
import 'rangy/lib/rangy-highlighter'
6+
7+
export default rangy

src/common/types.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1+
import { supportedLanguages } from './constant'
2+
13
export interface Config {
24
token: string
3-
targetLang: SupportLanguages
5+
targetLang: SupportLanguageKeys
46
region: APIRegions
7+
ocrSecretId?: string
8+
ocrSecretKey?: string
9+
hoverButton?: boolean
510
}
611

7-
export type SupportLanguages =
8-
| 'ZH'
9-
| 'EN'
10-
| 'JA'
11-
| 'DE'
12-
| 'FR'
13-
| 'ES'
14-
| 'PT'
15-
| 'IT'
16-
| 'NL'
17-
| 'PL'
18-
| 'RU'
12+
export type SupportLanguageKeys = keyof typeof supportedLanguages
1913

2014
export type APIRegions = 'default' | 'global' | 'dev'
2115

2216
export type TranslateResult = {
2317
translations: Array<{
24-
detected_source_language: SupportLanguages
18+
detected_source_language: SupportLanguageKeys
2519
text: string
2620
}>
2721
}

src/components/IconButton.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, {
55
ReactNode,
66
Ref,
77
} from 'react'
8-
import clsx from 'clsx'
8+
import tw from 'twin.macro'
99

1010
export interface BaseProps {
1111
children: ReactNode
@@ -26,8 +26,13 @@ const IconButton = forwardRef(function IconButton(
2626
<button
2727
{...props}
2828
ref={ref}
29-
className={clsx(['ate_IconButton', props.className])}
30-
onClick={handleClick}>
29+
onClick={handleClick}
30+
css={tw`
31+
inline-flex justify-center items-center w-auto h-auto m-0 p-2
32+
cursor-pointer text-center text-gray-800 no-underline rounded-md
33+
border border-solid border-gray-800 bg-white hover:bg-gray-100 active:bg-gray-200
34+
transition-colors ease-in-out duration-150
35+
`}>
3136
{props.children}
3237
</button>
3338
)

0 commit comments

Comments
 (0)