From e073ca6912df2778478ee0dddd27f1cd4d0b403c Mon Sep 17 00:00:00 2001 From: friebetill Date: Wed, 9 Nov 2022 11:46:51 +0100 Subject: [PATCH] Add option for formality --- src/deepl/deeplService.ts | 1 + src/deepl/fromLanguages.ts | 2 -- src/deepl/toLanguages.ts | 2 -- src/settings/pluginSettings.ts | 15 ++++++++++----- src/settings/settingTab.ts | 20 ++++++++++++++++++-- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/deepl/deeplService.ts b/src/deepl/deeplService.ts index dbdc1bc..0ecc8e7 100644 --- a/src/deepl/deeplService.ts +++ b/src/deepl/deeplService.ts @@ -37,6 +37,7 @@ export class DeepLService { text: preprocessedText, target_lang: toLanguage, ...(useFromLanguage && { source_lang: fromLanguage }), + formality: this.settings.formality, }).toString(), headers: { Authorization: `DeepL-Auth-Key ${this.settings.apiKey}`, diff --git a/src/deepl/fromLanguages.ts b/src/deepl/fromLanguages.ts index 0635a6f..6a75e87 100644 --- a/src/deepl/fromLanguages.ts +++ b/src/deepl/fromLanguages.ts @@ -1,5 +1,3 @@ -export const defaultFromLanguage = "AUTO"; - export const fromLanguages = { AUTO: "Detect language", BG: "Bulgarian", diff --git a/src/deepl/toLanguages.ts b/src/deepl/toLanguages.ts index 20c74cb..e29c49b 100644 --- a/src/deepl/toLanguages.ts +++ b/src/deepl/toLanguages.ts @@ -1,5 +1,3 @@ -export const defaultToLanguage = "DE"; - export const toLanguages: Record = { BG: "Bulgarian", CS: "Czech", diff --git a/src/settings/pluginSettings.ts b/src/settings/pluginSettings.ts index 91dbf19..668dddd 100644 --- a/src/settings/pluginSettings.ts +++ b/src/settings/pluginSettings.ts @@ -1,18 +1,23 @@ -import { defaultFromLanguage } from "src/deepl/fromLanguages"; -import { defaultToLanguage } from "src/deepl/toLanguages"; - export interface DeepLPluginSettings { apiKey: string; fromLanguage: string; toLanguage: string; showStatusBar: boolean; useProAPI: boolean; + formality: string; } +export const formalities: Record = { + default: "Default", + prefer_more: "More formal", + prefer_less: "Less formal", +}; + export const defaultSettings: Partial = { apiKey: "", - fromLanguage: defaultFromLanguage, - toLanguage: defaultToLanguage, + fromLanguage: "AUTO", + toLanguage: "DE", showStatusBar: true, useProAPI: false, + formality: "default", }; diff --git a/src/settings/settingTab.ts b/src/settings/settingTab.ts index 2be7f31..825c038 100644 --- a/src/settings/settingTab.ts +++ b/src/settings/settingTab.ts @@ -2,6 +2,7 @@ import { PluginSettingTab, Setting } from "obsidian"; import { toLanguages } from "src/deepl/toLanguages"; import DeepLPlugin from "../main"; import { fromLanguages } from "./../deepl/fromLanguages"; +import { formalities } from "./pluginSettings"; export class SettingTab extends PluginSettingTab { private plugin: DeepLPlugin; @@ -59,8 +60,23 @@ export class SettingTab extends PluginSettingTab { ); new Setting(containerEl) - .setName("Show in status bar") - .setDesc("Select the to language in the status bar.") + .setName("Formality") + .setDesc( + "Sets whether the translated text should lean towards formal or informal language." + ) + .addDropdown((dropdown) => + dropdown + .addOptions(formalities) + .setValue(this.plugin.settings.formality) + .onChange(async (value) => { + this.plugin.settings.formality = value; + await this.plugin.saveSettings(); + }) + ); + + new Setting(containerEl) + .setName("Show setting in status bar") + .setDesc('Select the "To language" in the status bar.') .addToggle((toggle) => toggle .setValue(this.plugin.settings.showStatusBar)