This README is written for adventurous users, developers and plugin reviewers, as an introductory guide to this hell of a mess that my code is. If you are instead looking for a guide on how to use this plugin, please refer to the tutorial.
Below you can find a brief description of the general code structure, files/folders indicated by
(!)
are the most significant code-wise, and will be described in more detail in the following sections.
/src/
├── README.md You are here!
├── /assets/ SCSS file containing all of the plugins styles + classes
├── constants.ts Has all constant values used by the plugin
├── /handlers/ (!) API wrappers of all translation services
├── helpers.ts Helper functions used throughout the plugin
├── l10n Localisation files
├── main.ts (!) Main plugin file
├── obsidian-util.ts Obsidian-specific utility functions
├── settings.ts Settings page constructor
├── stores.ts (!) Global stores that are used throughout the plugin
├── types.ts All types of the plugin
├── /ui/
│ ├── /animations/ Svelte animations
│ ├── /components/ Basic components (buttons, inputs, etc.)
│ ├── /modals/ Modals used by the plugin
│ ├── /obsidian-components/ Obsidian-specific components (SettingItem, ...)
│ └── /translator-components/ Main plugin components
│ ├── Reactivity.svelte (!) Handles all reactive actions
│ ├── SettingsPage.svelte Settings page + navbar component
│ ├── ViewPage.svelte (!) Translator View component
│ └── /settings-tabs/ (!) Setting tabs components
├── util.ts General utility functions
└── view.ts View constructor
Path: src/handlers
This folder contains API wrappers for all translation services. The services are set up in a hierarchical structure,
with src/handlers/dummy-translate.ts
being the base class. For more information on the handlers API, go to here.
Path: src/main.ts
This is the main plugin file, where the plugin is initialized and all the plugin functionality is set up.
You can find all the interactions with the Obsidian interface here, including executing commands, opening a
context menu on a note or files, and so on.
Path: src/stores.ts
This file contains all the global stores used by the plugin, some of which are reactive Svelte writables,
others simple objects. The currently used stores are:
settings
: Persistent plugin settings, changes made to this store are automatically saved to thedata.json
all_languages
: Key-value object of language locales to their display names (e.g.en: English
)available_languages
: The languages available for the global translator, changes based on filters setavailable_translator_services
: Translator services that the user can access, depends on platform and user-set settingsavailable_detector_services
: Language detector services that the user can access, depends on platform and user-set settingsspellcheck_languages
: Obsidian's set spellchecker languages, used as a filter on all languagesfasttext_data
: FastText model data, used for language detectionbergamot_data
: Bergamot model data, used for translationsettings_tab
: The currently active settings tabpassword
: Password used for encrypting the API keyspasswords_are_encrypted
: Whether the API keys are still encrypted or not (i.e. when password has not been given)glossary
dicts
: Dictionary of language pairs to their respective glossariesreplacements
: Glossary regex matching rules per language pair, case (in)sensitive based on settings
Path: src/ui/translator-components/Reactivity.svelte
This Svelte file is constructed on mount of the plugin, and will process all changes in settings, data, ...
such that all TranslatorViews etc. are all in sync. Also handles loading and unloading of translation services, the services
are managed and shared from active_services
.
Path: src/ui/translator-components/ViewPage.svelte
Implements the Translator View, every view has its own internal state, and makes use of a shared translator
object. Essentially a convenient-to-use front-end for the translator object.
Path: src/ui/translator-components/settings-tabs/
Contains all the individual settings pages: SettingsPage.svelte
contains a navbar, and
based on the tab selected in the navbar, the corresponding Settings Tab will be rendered.
Tab components:
AppearanceSettings.svelte
: Changing (default) appearance of plugin componentsDetectorSettings.svelte
: Options for theFastText
service, implements functionality for downloading and updating the serviceFunctionalitySettings.svelte
: Change default behaviour of the pluginGeneralSettings.svelte
: Changes the global translation service and its functionality, plus some security settingsGlossarySettings.svelte
: Interface for manipulating theglossary
object and adding/removing entries, plus updating a service's online glossaryHotkeySettings.svelte
: Change hotkeys for plugin actions, will automatically updateTranslatorSettings.svelte
: Default settings page shared for all translation services, acts as an interface for changing the service's authentication data, functionality and interacts with translator'svalidate()
andlanguages()
methods