Skip to content

Commit

Permalink
Add option for formality
Browse files Browse the repository at this point in the history
  • Loading branch information
friebetill committed Nov 9, 2022
1 parent 44e7016 commit e073ca6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/deepl/deeplService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
2 changes: 0 additions & 2 deletions src/deepl/fromLanguages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const defaultFromLanguage = "AUTO";

export const fromLanguages = {
AUTO: "Detect language",
BG: "Bulgarian",
Expand Down
2 changes: 0 additions & 2 deletions src/deepl/toLanguages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const defaultToLanguage = "DE";

export const toLanguages: Record<string, string> = {
BG: "Bulgarian",
CS: "Czech",
Expand Down
15 changes: 10 additions & 5 deletions src/settings/pluginSettings.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> = {
default: "Default",
prefer_more: "More formal",
prefer_less: "Less formal",
};

export const defaultSettings: Partial<DeepLPluginSettings> = {
apiKey: "",
fromLanguage: defaultFromLanguage,
toLanguage: defaultToLanguage,
fromLanguage: "AUTO",
toLanguage: "DE",
showStatusBar: true,
useProAPI: false,
formality: "default",
};
20 changes: 18 additions & 2 deletions src/settings/settingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e073ca6

Please sign in to comment.