Skip to content

Commit

Permalink
Removed configuration 'deepl.usePro' to improve usability
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenuhrbach committed Dec 20, 2023
1 parent c79a649 commit 6ba2034
Show file tree
Hide file tree
Showing 10 changed files with 809 additions and 721 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to the "vscode-deepl" extension will be documented in this f

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

### 1.0.8

- You no longer need to explicitly set "deepl.usePro" in the configuration to use the DeepL Pro API because its now determined based on the given api key

### 1.0.7

- Added new configuration options "defaultTargetLanguage" and "defaultSourceLanguage" to set global default languages.
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ You can store the API key via the following settings.
This extension contributes the following settings:

* `deepl.apiKey`: The key is used to authenticate with the DeepL API. [See offical documentation](https://www.deepl.com/docs-api/accessing-the-api/authentication/)
* `deepl.usePro`: Whether to use the DeepL Pro API - check this option if you use the paid plan.

For this extension to work, the above settings must be made.

Expand Down Expand Up @@ -71,6 +70,10 @@ Dont use this extension if you dont agree with their privacy policy!

## Release Notes

### 1.0.8

- You no longer need to explicitly set "deepl.usePro" in the configuration to use the DeepL Pro API because its now determined based on the given api key

### 1.0.7

- Added new configuration options "defaultTargetLanguage" and "defaultSourceLanguage" to set global default languages.
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-deepl",
"displayName": "DeepL for Visual Studio Code",
"description": "Easily translate into more than 25 languages directly from your favourite editor using DeepL.",
"version": "1.0.7",
"version": "1.0.8",
"keywords": [
"DeepL",
"Translate",
Expand Down Expand Up @@ -50,11 +50,6 @@
"default": "",
"markdownDescription": "The key is used to authenticate with the DeepL API. [See offical documentation](https://www.deepl.com/docs-api/accessing-the-api/authentication/)"
},
"deepl.usePro": {
"type": "boolean",
"default": false,
"description": "Whether to use the DeepL Pro API"
},
"deepl.formality": {
"type": "string",
"default": "default",
Expand Down Expand Up @@ -280,6 +275,7 @@
},
"dependencies": {
"axios": "^1.6.0",
"deepl-node": "^1.11.0",
"vue": "^3.1.5",
"xstate": "^4.23.0"
}
Expand Down
3 changes: 1 addition & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as debug from './debug';
import * as vscode from 'vscode';
import { state } from './state';
import { showMessageWithTimeout } from './vscode';
import { showApiKeyInput, showSourceLanguageInput, showTargetLanguageInput, showUseProInput } from "./inputs";
import { showApiKeyInput, showSourceLanguageInput, showTargetLanguageInput } from "./inputs";
import { TranslateCommandParam, TranslateParam } from './types';
import { getDefaultSourceLanguage, getDefaultTargetLanguage } from './helper';

Expand Down Expand Up @@ -111,5 +111,4 @@ export const configureSettings = async () => {
if (!state.apiKey) {
return;
}
state.usePro = await showUseProInput();
};
7 changes: 4 additions & 3 deletions src/deepl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from 'axios';
import { state } from './state';
import { Language, LanguageType, Translation } from './types';
import { isFreeAccountAuthKey } from 'deepl-node';

/* eslint-disable */
export enum DeepLErrorCodes {
Expand Down Expand Up @@ -62,9 +63,9 @@ const errorHandlers: ErrorHandler[] = [];
const formalityAllowed: string[] = ["DE", "FR", "IT", "ES", "NL", "PL", "PT-PT", "PT-BR", "RU"];

http.interceptors.request.use((config) => {
config.baseURL = state.usePro
? 'https://api.deepl.com'
: 'https://api-free.deepl.com';
config.baseURL = isFreeAccountAuthKey(state.apiKey!)
? 'https://api-free.deepl.com'
: 'https://api.deepl.com';

if (!config.params) {
config.params = {};
Expand Down
11 changes: 0 additions & 11 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,4 @@ export function showApiKeyInput() {
placeHolder: 'Please enter your DeepL API key',
ignoreFocusOut: true
}).then(x => x ?? null);
}

export function showUseProInput() {
return vscode.window.showQuickPick(
['No', 'Yes'],
{
title: 'Do you want to use the DeepL Pro API?',
placeHolder: 'Do you want to use the DeepL Pro API?',
ignoreFocusOut: true
}
).then(x => x === 'Yes');
}
6 changes: 1 addition & 5 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const state = reactive<ExtensionState>({
targetLanguage: null,
sourceLanguage: null,
apiKey: null,
usePro: false,
tagHandling: "off",
ignoreTags: "",
nonSplittingTags: "",
Expand All @@ -34,7 +33,6 @@ export function setup(context: vscode.ExtensionContext) {

const config = vscode.workspace.getConfiguration('deepl');

state.usePro = config.get('usePro') ?? false;
state.apiKey = config.get('apiKey') ?? null;
state.formality = config.get('formality') ?? "default";
state.ignoreTags = config.get('ignoreTags') ?? "";
Expand All @@ -50,7 +48,6 @@ export function setup(context: vscode.ExtensionContext) {
debug.write(`Initialized extension using state:`);
debug.write(JSON.stringify(state, null, 2));

watch(() => state.usePro, () => config.update('usePro', state.usePro, vscode.ConfigurationTarget.Global));
watch(() => state.apiKey, () => config.update('apiKey', state.apiKey, vscode.ConfigurationTarget.Global));
watch(() => state.formality, () => config.update('formality', state.formality, vscode.ConfigurationTarget.Global));
watch(() => state.ignoreTags, () => config.update('ignoreTags', state.ignoreTags, vscode.ConfigurationTarget.Global));
Expand All @@ -70,9 +67,8 @@ export function setup(context: vscode.ExtensionContext) {

debug.write(`Extension configuration has changed! Updating extension state...`);

const { usePro, apiKey, formality, splitSentences, tagHandling, ignoreTags, preserveFormatting, splittingTags, nonSplittingTags, glossaryId, defaultTargetLanguage, defaultSourceLanguage } = vscode.workspace.getConfiguration('deepl');
const { apiKey, formality, splitSentences, tagHandling, ignoreTags, preserveFormatting, splittingTags, nonSplittingTags, glossaryId, defaultTargetLanguage, defaultSourceLanguage } = vscode.workspace.getConfiguration('deepl');

state.usePro = usePro;
state.apiKey = apiKey;
state.formality = formality;
state.ignoreTags = ignoreTags;
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export interface ExtensionState {
targetLanguage: string | null,
sourceLanguage: string | null,
apiKey: string | null,
usePro: boolean,
tagHandling: 'html' | 'xml' | 'off',
ignoreTags: string,
formality: string,
Expand Down
2 changes: 1 addition & 1 deletion src/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const sleep = (timeout: number) => new Promise(resolve => {
export const waitFor = async (timeout: number, condition: () => boolean): Promise<boolean> => {
while (!condition() && timeout > 0) {
timeout -= 100;
await sleep(100)
await sleep(100);
}

return timeout > 0 ? true : false;
Expand Down
Loading

0 comments on commit 6ba2034

Please sign in to comment.