3 - Finalised adding support for German.

This commit is contained in:
Caleb Campbell
2025-12-27 13:38:14 +11:00
parent 2bcf3cb980
commit 59d66a247e
4 changed files with 33 additions and 22 deletions

View File

@@ -1,3 +1,4 @@
import { getLanguage } from 'obsidian';
import { I18N } from './i18n';
import { Book } from './i18n/models';
@@ -54,10 +55,11 @@ export default class PassageReference
/** Builds the passage matching regular expression. */
static get regExp(): RegExp {
const books = getBooksByLanguage();
let regExpString = '^\\-\\- ?(';
regExpString += I18N.EN.BOOKS.map(
(b) => `${b.name}|${b.aliases.join('|')}`
).join('|');
regExpString += books
.map((b) => `${b.name}|${b.aliases.join('|')}`)
.join('|');
regExpString +=
') ?(\\d{1,3}(?::\\d{1,3})?' +
'(?: ?\\- ?\\d{1,3}(?::\\d{1,3})?)?)' +
@@ -152,8 +154,9 @@ export default class PassageReference
/** Retrieves a book based on its alias. */
private static getBook(alias: string): Book | undefined {
const books = getBooksByLanguage();
alias = alias.toLowerCase();
return I18N.EN.BOOKS.find((book) => {
return books.find((book) => {
const aliases = book.aliases.map((a) => a.toLowerCase());
if (book.name.toLowerCase() === alias) return book;
if (aliases.includes(alias)) return book;
@@ -207,6 +210,16 @@ export default class PassageReference
}
}
function getBooksByLanguage(): Book[] {
switch (getLanguage()) {
case 'de':
return I18N.DE.BOOKS;
case 'en':
default:
return I18N.EN.BOOKS;
}
}
export enum PassageFormat {
Manuscript = 'manuscript',
Paragraph = 'paragraph',