diff options
author | 2022-08-17 22:54:41 +0100 | |
---|---|---|
committer | 2022-08-17 22:54:41 +0100 | |
commit | fb0cc81d1db0d88c90bb112a0caec66095fcc0f0 (patch) | |
tree | aaa5d0f92f55ccf3984af2cbf2ebbcb1da5fd7c6 /src/containers/settings | |
parent | 6.0.1-nightly.16 [skip ci] (diff) | |
download | ferdium-app-fb0cc81d1db0d88c90bb112a0caec66095fcc0f0.tar.gz ferdium-app-fb0cc81d1db0d88c90bb112a0caec66095fcc0f0.tar.zst ferdium-app-fb0cc81d1db0d88c90bb112a0caec66095fcc0f0.zip |
Feature: Add Ferdium Translator (#548)
Add feature to translate text natively using https://github.com/shikar/NODE_GOOGLE_TRANSLATE package and a LibreTranslate self-hosted option (already running on our server on https://translator.ferdium.org).
Diffstat (limited to 'src/containers/settings')
-rw-r--r-- | src/containers/settings/EditSettingsScreen.tsx | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/containers/settings/EditSettingsScreen.tsx b/src/containers/settings/EditSettingsScreen.tsx index fbbed629a..a4d7ba0eb 100644 --- a/src/containers/settings/EditSettingsScreen.tsx +++ b/src/containers/settings/EditSettingsScreen.tsx | |||
@@ -15,6 +15,10 @@ import { | |||
15 | ICON_SIZES, | 15 | ICON_SIZES, |
16 | NAVIGATION_BAR_BEHAVIOURS, | 16 | NAVIGATION_BAR_BEHAVIOURS, |
17 | SEARCH_ENGINE_NAMES, | 17 | SEARCH_ENGINE_NAMES, |
18 | TRANSLATOR_ENGINE_NAMES, | ||
19 | GOOGLE_TRANSLATOR_LANGUAGES, | ||
20 | TRANSLATOR_ENGINE_GOOGLE, | ||
21 | LIBRETRANSLATE_TRANSLATOR_LANGUAGES, | ||
18 | TODO_APPS, | 22 | TODO_APPS, |
19 | DEFAULT_SETTING_KEEP_ALL_WORKSPACES_LOADED, | 23 | DEFAULT_SETTING_KEEP_ALL_WORKSPACES_LOADED, |
20 | DEFAULT_IS_FEATURE_ENABLED_BY_USER, | 24 | DEFAULT_IS_FEATURE_ENABLED_BY_USER, |
@@ -103,6 +107,14 @@ const messages = defineMessages({ | |||
103 | id: 'settings.app.form.searchEngine', | 107 | id: 'settings.app.form.searchEngine', |
104 | defaultMessage: 'Search engine', | 108 | defaultMessage: 'Search engine', |
105 | }, | 109 | }, |
110 | translatorEngine: { | ||
111 | id: 'settings.app.form.translatorEngine', | ||
112 | defaultMessage: 'Translator Engine', | ||
113 | }, | ||
114 | translatorLanguage: { | ||
115 | id: 'settings.app.form.translatorLanguage', | ||
116 | defaultMessage: 'Default Translator language', | ||
117 | }, | ||
106 | hibernateOnStartup: { | 118 | hibernateOnStartup: { |
107 | id: 'settings.app.form.hibernateOnStartup', | 119 | id: 'settings.app.form.hibernateOnStartup', |
108 | defaultMessage: 'Keep services in hibernation on startup', | 120 | defaultMessage: 'Keep services in hibernation on startup', |
@@ -267,6 +279,10 @@ const messages = defineMessages({ | |||
267 | id: 'settings.app.form.enableSpellchecking', | 279 | id: 'settings.app.form.enableSpellchecking', |
268 | defaultMessage: 'Enable spell checking', | 280 | defaultMessage: 'Enable spell checking', |
269 | }, | 281 | }, |
282 | enableTranslator: { | ||
283 | id: 'settings.app.form.enableTranslator', | ||
284 | defaultMessage: 'Enable Translator', | ||
285 | }, | ||
270 | enableGPUAcceleration: { | 286 | enableGPUAcceleration: { |
271 | id: 'settings.app.form.enableGPUAcceleration', | 287 | id: 'settings.app.form.enableGPUAcceleration', |
272 | defaultMessage: 'Enable GPU Acceleration', | 288 | defaultMessage: 'Enable GPU Acceleration', |
@@ -342,6 +358,8 @@ class EditSettingsScreen extends Component<EditSettingsScreenProps> { | |||
342 | notifyTaskBarOnMessage: Boolean(settingsData.notifyTaskBarOnMessage), | 358 | notifyTaskBarOnMessage: Boolean(settingsData.notifyTaskBarOnMessage), |
343 | navigationBarBehaviour: settingsData.navigationBarBehaviour, | 359 | navigationBarBehaviour: settingsData.navigationBarBehaviour, |
344 | searchEngine: settingsData.searchEngine, | 360 | searchEngine: settingsData.searchEngine, |
361 | translatorEngine: settingsData.translatorEngine, | ||
362 | translatorLanguage: settingsData.translatorLanguage, | ||
345 | hibernateOnStartup: Boolean(settingsData.hibernateOnStartup), | 363 | hibernateOnStartup: Boolean(settingsData.hibernateOnStartup), |
346 | hibernationStrategy: Number(settingsData.hibernationStrategy), | 364 | hibernationStrategy: Number(settingsData.hibernationStrategy), |
347 | wakeUpStrategy: Number(settingsData.wakeUpStrategy), | 365 | wakeUpStrategy: Number(settingsData.wakeUpStrategy), |
@@ -394,6 +412,7 @@ class EditSettingsScreen extends Component<EditSettingsScreenProps> { | |||
394 | ), | 412 | ), |
395 | showDragArea: Boolean(settingsData.showDragArea), | 413 | showDragArea: Boolean(settingsData.showDragArea), |
396 | enableSpellchecking: Boolean(settingsData.enableSpellchecking), | 414 | enableSpellchecking: Boolean(settingsData.enableSpellchecking), |
415 | enableTranslator: Boolean(settingsData.enableTranslator), | ||
397 | spellcheckerLanguage: settingsData.spellcheckerLanguage, | 416 | spellcheckerLanguage: settingsData.spellcheckerLanguage, |
398 | userAgentPref: settingsData.userAgentPref, | 417 | userAgentPref: settingsData.userAgentPref, |
399 | beta: Boolean(settingsData.beta), // we need this info in the main process as well | 418 | beta: Boolean(settingsData.beta), // we need this info in the main process as well |
@@ -451,6 +470,16 @@ class EditSettingsScreen extends Component<EditSettingsScreenProps> { | |||
451 | sort: false, | 470 | sort: false, |
452 | }); | 471 | }); |
453 | 472 | ||
473 | const translatorEngines = getSelectOptions({ | ||
474 | locales: TRANSLATOR_ENGINE_NAMES, | ||
475 | sort: false, | ||
476 | }); | ||
477 | |||
478 | const translatorLanguages = getSelectOptions({ | ||
479 | locales: LIBRETRANSLATE_TRANSLATOR_LANGUAGES, | ||
480 | sort: false, | ||
481 | }); | ||
482 | |||
454 | const hibernationStrategies = getSelectOptions({ | 483 | const hibernationStrategies = getSelectOptions({ |
455 | locales: HIBERNATION_STRATEGIES, | 484 | locales: HIBERNATION_STRATEGIES, |
456 | sort: false, | 485 | sort: false, |
@@ -574,6 +603,18 @@ class EditSettingsScreen extends Component<EditSettingsScreenProps> { | |||
574 | default: DEFAULT_APP_SETTINGS.searchEngine, | 603 | default: DEFAULT_APP_SETTINGS.searchEngine, |
575 | options: searchEngines, | 604 | options: searchEngines, |
576 | }, | 605 | }, |
606 | translatorEngine: { | ||
607 | label: intl.formatMessage(messages.translatorEngine), | ||
608 | value: settings.all.app.translatorEngine, | ||
609 | default: DEFAULT_APP_SETTINGS.translatorEngine, | ||
610 | options: translatorEngines, | ||
611 | }, | ||
612 | translatorLanguage: { | ||
613 | label: intl.formatMessage(messages.translatorLanguage), | ||
614 | value: settings.all.app.translatorLanguage, | ||
615 | default: DEFAULT_APP_SETTINGS.translatorLanguage, | ||
616 | options: translatorLanguages, | ||
617 | }, | ||
577 | hibernateOnStartup: { | 618 | hibernateOnStartup: { |
578 | label: intl.formatMessage(messages.hibernateOnStartup), | 619 | label: intl.formatMessage(messages.hibernateOnStartup), |
579 | value: settings.all.app.hibernateOnStartup, | 620 | value: settings.all.app.hibernateOnStartup, |
@@ -677,6 +718,11 @@ class EditSettingsScreen extends Component<EditSettingsScreenProps> { | |||
677 | value: settings.all.app.enableSpellchecking, | 718 | value: settings.all.app.enableSpellchecking, |
678 | default: DEFAULT_APP_SETTINGS.enableSpellchecking, | 719 | default: DEFAULT_APP_SETTINGS.enableSpellchecking, |
679 | }, | 720 | }, |
721 | enableTranslator: { | ||
722 | label: intl.formatMessage(messages.enableTranslator), | ||
723 | value: settings.all.app.enableTranslator, | ||
724 | default: DEFAULT_APP_SETTINGS.enableTranslator, | ||
725 | }, | ||
680 | spellcheckerLanguage: { | 726 | spellcheckerLanguage: { |
681 | label: intl.formatMessage(globalMessages.spellcheckerLanguage), | 727 | label: intl.formatMessage(globalMessages.spellcheckerLanguage), |
682 | value: settings.all.app.spellcheckerLanguage, | 728 | value: settings.all.app.spellcheckerLanguage, |
@@ -828,6 +874,14 @@ class EditSettingsScreen extends Component<EditSettingsScreenProps> { | |||
828 | }, | 874 | }, |
829 | }; | 875 | }; |
830 | 876 | ||
877 | if (settings.app.translatorEngine === TRANSLATOR_ENGINE_GOOGLE) { | ||
878 | const translatorGoogleLanguages = getSelectOptions({ | ||
879 | locales: GOOGLE_TRANSLATOR_LANGUAGES, | ||
880 | sort: false, | ||
881 | }); | ||
882 | config.fields.translatorLanguage.options = translatorGoogleLanguages; | ||
883 | } | ||
884 | |||
831 | if (workspaces.isFeatureActive) { | 885 | if (workspaces.isFeatureActive) { |
832 | config.fields.keepAllWorkspacesLoaded = { | 886 | config.fields.keepAllWorkspacesLoaded = { |
833 | label: intl.formatMessage(messages.keepAllWorkspacesLoaded), | 887 | label: intl.formatMessage(messages.keepAllWorkspacesLoaded), |