3 - Made progress.

This commit is contained in:
Caleb Campbell
2025-12-26 10:18:51 +11:00
parent 054744e35b
commit d01f4bec2e
5 changed files with 94 additions and 47 deletions

View File

@@ -1,11 +1,11 @@
import { Settings } from '../models'; import { SettingsLabels } from '../models';
export const SETTINGS: Settings = { export const SETTINGS: SettingsLabels = {
required: { required: {
name: 'Required Settings', name: 'Required Settings',
controls: { controls: {
biblesPath: { biblesPath: {
name: 'Bibles path', name: 'Bible pathen',
description: 'The path to the folder containing your bibles.', description: 'The path to the folder containing your bibles.',
placeholder: 'e.g. Data/Bibles', placeholder: 'e.g. Data/Bibles',
}, },

View File

@@ -1,6 +1,6 @@
import { Settings } from '../models'; import { SettingsLabels } from '../models';
export const SETTINGS: Settings = { export const SETTINGS: SettingsLabels = {
required: { required: {
name: 'Required Settings', name: 'Required Settings',
controls: { controls: {

View File

@@ -4,18 +4,48 @@ export interface Book {
aliases: string[]; aliases: string[];
} }
export interface Settings { export interface SettingsLabels {
[key: string]: SettingsGroup; required: {
}
interface SettingsGroup {
name: string; name: string;
description?: string; controls: {
controls: { [key: string]: Control }; biblesPath: ControlWithPlaceholder;
};
};
optional: {
name: string;
controls: {
defaultVersion: ControlWithPlaceholder;
defaultPassageFormat: Control;
bibleFormat: Control;
};
};
quoteFormat: {
name: string;
description: string;
controls: {
includeReference: Control;
referencePosition: Control;
linkToPassage: Control;
};
};
calloutFormat: {
name: string;
description: string;
controls: {
calloutType: Control;
linkToPassage: Control;
};
};
} }
interface Control { interface Control {
name: string; name: string;
description?: string; description: string;
placeholder?: string; }
interface ControlWithPlaceholder extends Control {
placeholder: string;
} }

View File

@@ -1,6 +1,7 @@
import LocalBibleRefPlugin from 'main'; import LocalBibleRefPlugin from 'main';
import { import {
App, App,
getLanguage,
normalizePath, normalizePath,
Notice, Notice,
PluginSettingTab, PluginSettingTab,
@@ -11,28 +12,47 @@ import { PassageFormat } from './passage-reference';
import PathSuggest from './path-suggest'; import PathSuggest from './path-suggest';
import { CalloutType, QuoteReferencePosition } from './settings'; import { CalloutType, QuoteReferencePosition } from './settings';
import VersionSuggest from './version-suggest'; import VersionSuggest from './version-suggest';
import { SettingsLabels } from './i18n/models';
import { I18N } from './i18n';
// STILL TODO:
// - Need to add a 'common' labels internationalization file for non-settings labels. (e.g. notices)
// - Need to sort out books in PassageReference to use I18N.
export default class LocalBibleRefSettingTab extends PluginSettingTab { export default class LocalBibleRefSettingTab extends PluginSettingTab {
private plugin: LocalBibleRefPlugin; private plugin: LocalBibleRefPlugin;
private settingsLabels: SettingsLabels;
constructor(app: App, plugin: LocalBibleRefPlugin) { constructor(app: App, plugin: LocalBibleRefPlugin) {
super(app, plugin); super(app, plugin);
this.plugin = plugin; this.plugin = plugin;
switch (getLanguage()) {
case 'de':
this.settingsLabels = I18N.DE.SETTINGS;
break;
case 'en':
default:
this.settingsLabels = I18N.EN.SETTINGS;
break;
}
} }
display(): void { display(): void {
const { containerEl } = this; const { containerEl } = this;
const { required, optional, quoteFormat, calloutFormat } =
this.settingsLabels;
containerEl.empty(); containerEl.empty();
new Setting(containerEl).setName('Required Settings').setHeading(); new Setting(containerEl).setName(required.name).setHeading();
let biblesPathTimeout: number; let biblesPathTimeout: number;
new Setting(containerEl) new Setting(containerEl)
.setName('Bibles path') .setName(required.controls.biblesPath.name)
.setDesc('The path to the folder containing your bibles.') .setDesc(required.controls.biblesPath.description)
.addText((text) => { .addText((text) => {
text text
.setPlaceholder('e.g. Data/Bibles') .setPlaceholder(required.controls.biblesPath.placeholder)
.setValue(this.plugin.settings.biblesPath) .setValue(this.plugin.settings.biblesPath)
.onChange(async (value) => { .onChange(async (value) => {
// toggle visibility of default version setting // toggle visibility of default version setting
@@ -65,17 +85,15 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
new PathSuggest(this.app, text.inputEl); new PathSuggest(this.app, text.inputEl);
}); });
new Setting(containerEl).setName('Optional Settings').setHeading(); new Setting(containerEl).setName(optional.name).setHeading();
let defaultVersionTimeout: number; let defaultVersionTimeout: number;
const defaultVersionSetting = new Setting(containerEl) const defaultVersionSetting = new Setting(containerEl)
.setName('Default version') .setName(optional.controls.defaultVersion.name)
.setDesc( .setDesc(optional.controls.defaultVersion.description)
'The version to use by default - shorthand. This should correspond to a folder in the bibles folder selected above.'
)
.addText((text) => { .addText((text) => {
text text
.setPlaceholder('e.g. NIV') .setPlaceholder(optional.controls.defaultVersion.placeholder)
.setValue(this.plugin.settings.defaultVersionShorthand) .setValue(this.plugin.settings.defaultVersionShorthand)
.onChange(async (value) => { .onChange(async (value) => {
this.plugin.settings.defaultVersionShorthand = value; this.plugin.settings.defaultVersionShorthand = value;
@@ -101,8 +119,8 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
} }
new Setting(containerEl) new Setting(containerEl)
.setName('Default passage format') .setName(optional.controls.defaultPassageFormat.name)
.setDesc('The markdown format to use for passages by default.') .setDesc(optional.controls.defaultPassageFormat.description)
.addDropdown((dropdown) => .addDropdown((dropdown) =>
dropdown dropdown
.addOptions({ .addOptions({
@@ -119,10 +137,8 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
); );
new Setting(containerEl) new Setting(containerEl)
.setName('Bible Format') .setName(optional.controls.bibleFormat.name)
.setDesc( .setDesc(optional.controls.bibleFormat.description)
'The formatting style you use for your vault bibles. Local Bible Ref relies on this to parse passages correctly.'
)
.addDropdown((dropdown) => .addDropdown((dropdown) =>
dropdown dropdown
.addOptions({ .addOptions({
@@ -137,13 +153,13 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
); );
new Setting(containerEl) new Setting(containerEl)
.setName('Quote Format Settings') .setName(quoteFormat.name)
.setDesc('Settings for the quote passage format.') .setDesc(quoteFormat.description)
.setHeading(); .setHeading();
new Setting(containerEl) new Setting(containerEl)
.setName('Include reference') .setName(quoteFormat.controls.includeReference.name)
.setDesc('Whether to include a reference to the passage.') .setDesc(quoteFormat.controls.includeReference.description)
.addToggle((toggle) => .addToggle((toggle) =>
toggle toggle
.setValue(this.plugin.settings.quote.includeReference) .setValue(this.plugin.settings.quote.includeReference)
@@ -169,8 +185,8 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
); );
const quoteRefPositionSetting = new Setting(containerEl) const quoteRefPositionSetting = new Setting(containerEl)
.setName('Reference position') .setName(quoteFormat.controls.referencePosition.name)
.setDesc('Where to position the reference.') .setDesc(quoteFormat.controls.referencePosition.description)
.addDropdown((dropdown) => .addDropdown((dropdown) =>
dropdown dropdown
.addOptions({ .addOptions({
@@ -186,8 +202,8 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
); );
const quoteRefLinkSetting = new Setting(containerEl) const quoteRefLinkSetting = new Setting(containerEl)
.setName('Link to passage') .setName(quoteFormat.controls.linkToPassage.name)
.setDesc('Whether the reference should link to the passage in the Bible.') .setDesc(quoteFormat.controls.linkToPassage.description)
.addToggle((toggle) => .addToggle((toggle) =>
toggle toggle
.setValue(this.plugin.settings.quote.linkToPassage) .setValue(this.plugin.settings.quote.linkToPassage)
@@ -206,13 +222,13 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
} }
new Setting(containerEl) new Setting(containerEl)
.setName('Callout Format Settings') .setName(calloutFormat.name)
.setDesc('Settings for the callout passage format.') .setDesc(calloutFormat.description)
.setHeading(); .setHeading();
new Setting(containerEl) new Setting(containerEl)
.setName('Callout type') .setName(calloutFormat.controls.calloutType.name)
.setDesc('The type of callout to use for passages.') .setDesc(calloutFormat.controls.calloutType.description)
.addDropdown((dropdown) => .addDropdown((dropdown) =>
dropdown dropdown
.addOptions({ .addOptions({
@@ -238,8 +254,8 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
); );
new Setting(containerEl) new Setting(containerEl)
.setName('Link to passage') .setName(calloutFormat.controls.linkToPassage.name)
.setDesc('Whether the reference should link to the passage in the Bible.') .setDesc(calloutFormat.controls.linkToPassage.description)
.addToggle((toggle) => .addToggle((toggle) =>
toggle toggle
.setValue(this.plugin.settings.callout.linkToPassage) .setValue(this.plugin.settings.callout.linkToPassage)

View File

@@ -1,4 +1,5 @@
import { Book, BOOKS_EN } from './books/books.en'; import { I18N } from './i18n';
import { Book } from './i18n/models';
export default class PassageReference export default class PassageReference
implements ChapterReference, PassageOptions implements ChapterReference, PassageOptions
@@ -54,7 +55,7 @@ export default class PassageReference
/** Builds the passage matching regular expression. */ /** Builds the passage matching regular expression. */
static get regExp(): RegExp { static get regExp(): RegExp {
let regExpString = '^\\-\\- ?('; let regExpString = '^\\-\\- ?(';
regExpString += BOOKS_EN.map( regExpString += I18N.EN.BOOKS.map(
(b) => `${b.name}|${b.aliases.join('|')}` (b) => `${b.name}|${b.aliases.join('|')}`
).join('|'); ).join('|');
regExpString += regExpString +=
@@ -152,7 +153,7 @@ export default class PassageReference
/** Retrieves a book based on its alias. */ /** Retrieves a book based on its alias. */
private static getBook(alias: string): Book | undefined { private static getBook(alias: string): Book | undefined {
alias = alias.toLowerCase(); alias = alias.toLowerCase();
return BOOKS_EN.find((book) => { return I18N.EN.BOOKS.find((book) => {
const aliases = book.aliases.map((a) => a.toLowerCase()); const aliases = book.aliases.map((a) => a.toLowerCase());
if (book.name.toLowerCase() === alias) return book; if (book.name.toLowerCase() === alias) return book;
if (aliases.includes(alias)) return book; if (aliases.includes(alias)) return book;