Skip to content

Commit

Permalink
~ Small redesign of list interface
Browse files Browse the repository at this point in the history
+ Ability to translate plugin into different languages(References #43)
+ Translated into german(References #43)
  • Loading branch information
joethei committed Dec 1, 2021
1 parent 20fbe94 commit 123356b
Show file tree
Hide file tree
Showing 21 changed files with 557 additions and 245 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "rss-reader",
"name": "RSS Reader",
"version": "0.7.0",
"version": "0.7.1",
"minAppVersion": "0.9.12",
"description": "Read RSS Feeds from within obsidian",
"author": "Johannes Theiner",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rss-reader",
"version": "0.6.6",
"version": "0.7.1",
"description": "Read RSS Feeds from inside obsidian",
"main": "main.js",
"scripts": {
Expand Down
23 changes: 12 additions & 11 deletions src/actions/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,28 @@ import RssReaderPlugin from "../main";
import {htmlToMarkdown, Notice} from "obsidian";
import {copy} from "obsidian-community-lib";
import {TagModal} from "../modals/TagModal";
import t from "../l10n/locale";

export default class Action {

static CREATE_NOTE = new Action("create new note", "create-new", (plugin, item) : Promise<void> => {
static CREATE_NOTE = new Action(t("create_note"), "create-new", (plugin, item) : Promise<void> => {
return createNewNote(plugin, item);
});

static PASTE = new Action("paste to current note", "paste", (plugin, item) : Promise<void> => {
static PASTE = new Action(t("paste_to_note"), "paste", (plugin, item) : Promise<void> => {
return pasteToNote(plugin, item);
});

static COPY = new Action("copy to clipboard", "feather-clipboard", ((_, item) : Promise<void> => {
static COPY = new Action(t("copy_to_clipboard"), "feather-clipboard", ((_, item) : Promise<void> => {
return copy(htmlToMarkdown(item.content));
}));

static OPEN = new Action("open in browser", "open-elsewhere-glyph", ((_, item) : Promise<void> => {
static OPEN = new Action(t("open_browser"), "open-elsewhere-glyph", ((_, item) : Promise<void> => {
openInBrowser(item);
return Promise.resolve();
}));

static TAGS = new Action("edit tags", "tag-glyph", (((plugin, item) => {
static TAGS = new Action(t("edit_tags"), "tag-glyph", (((plugin, item) => {
const modal = new TagModal(plugin, item.tags);

modal.onClose = async () => {
Expand All @@ -39,13 +40,13 @@ export default class Action {
return Promise.resolve();
})));

static READ = new Action("Mark as read/unread", "feather-eye", ((async (plugin, item) : Promise<void> => {
static READ = new Action(t("mark_as_read_unread"), "feather-eye", ((async (plugin, item) : Promise<void> => {
if (item.read) {
item.read = false;
new Notice("marked item as unread");
new Notice(t("marked_as_unread"));
} else {
item.read = true;
new Notice("marked item as read");
new Notice(t("marked_as_read"));
}
const items = plugin.settings.items;
await plugin.writeFeedContent(() => {
Expand All @@ -54,13 +55,13 @@ export default class Action {
return Promise.resolve();
})));

static FAVORITE = new Action("Mark as Favorite/remove from favorites", "star", ((async (plugin, item) : Promise<void> => {
static FAVORITE = new Action(t("mark_as_favorite_remove"), "star", ((async (plugin, item) : Promise<void> => {
if (item.favorite) {
item.favorite = false;
new Notice("removed item from favorites");
new Notice(t("removed_from_favorites"));
} else {
item.favorite = true;
new Notice("marked item as favorite");
new Notice(t("added_to_favorites"));
}
const items = plugin.settings.items;
await plugin.writeFeedContent(() => {
Expand Down
15 changes: 8 additions & 7 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {FILE_NAME_REGEX} from "./consts";
import {isInVault} from "obsidian-community-lib";
import RssReaderPlugin from "./main";
import {RssReaderSettings} from "./settings/settings";
import t from "./l10n/locale";

export async function createNewNote(plugin: RssReaderPlugin, item: RssFeedItem) : Promise<void> {
const activeFile = plugin.app.workspace.getActiveFile();
Expand All @@ -16,19 +17,19 @@ export async function createNewNote(plugin: RssReaderPlugin, item: RssFeedItem)
//make sure there are no slashes in the title.
const title = item.title.replace(/[\/\\:]/g, ' ');

const inputPrompt = new TextInputPrompt(plugin.app, "Please specify a file name", "cannot contain: * \" \\ / < > : | ?", title, title);
const inputPrompt = new TextInputPrompt(plugin.app, t("specify_name"), t("cannot_contain") + " * \" \\ / < > : | ?", title, title);
if(plugin.settings.askForFilename) {
await inputPrompt
.openAndGetValue(async (text: TextComponent) => {
const value = text.getValue();
if(value.match(FILE_NAME_REGEX)) {
inputPrompt.setValidationError(text, "that filename is not valid");
inputPrompt.setValidationError(text, t("invalid_filename"));
return;
}
const filePath = normalizePath([dir, `${value}.md`].join('/'));

if (isInVault(plugin.app, filePath, '')) {
inputPrompt.setValidationError(text, "there is already a note with that name");
inputPrompt.setValidationError(text, t("note_exists"));
return;
}
inputPrompt.close();
Expand All @@ -45,7 +46,7 @@ export async function createNewNote(plugin: RssReaderPlugin, item: RssFeedItem)

async function createNewFile(plugin: RssReaderPlugin, item: RssFeedItem, path: string, title: string) {
if (isInVault(plugin.app, path, '')) {
new Notice("there is already a note with that name");
new Notice(t("note_exists"));
return;
}

Expand All @@ -63,13 +64,13 @@ async function createNewFile(plugin: RssReaderPlugin, item: RssFeedItem, path: s
return items;
});

new Notice("Created note from article");
new Notice(t("created_note"));
}

export async function pasteToNote(plugin: RssReaderPlugin, item: RssFeedItem) : Promise<void> {
const file = plugin.app.workspace.getActiveFile();
if (file === null) {
new Notice("no file active");
new Notice(t("no_file_active"));
return;
}

Expand All @@ -86,7 +87,7 @@ export async function pasteToNote(plugin: RssReaderPlugin, item: RssFeedItem) :
return items;
});

new Notice("inserted article into note");
new Notice(t("RSS_Reader") + t("inserted_article"));
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/l10n/locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//taken from https://github.com/valentine195/obsidian-leaflet-plugin/blob/master/src/l10n/locale.ts
import en from "./locales/en";
import de from "./locales/de";

const locale = window.moment.locale;

const localeMap: { [k: string]: Partial<typeof en> } = {
en,
de
};

const userLocale = localeMap[locale()];

export default function t(str: keyof typeof en, ...inserts: string[]): string {
let localeStr = (userLocale && userLocale[str]) ?? en[str];

for (let i = 0; i < inserts.length; i++) {
localeStr = localeStr.replace(`%${i + 1}`, inserts[i]);
}

return localeStr;
}
127 changes: 127 additions & 0 deletions src/l10n/locales/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
export default {
RSS_Reader: "RSS Reader",
RSS_Feeds: "RSS Feeds",

//commands
open: "Öffnen",
refresh_feeds: "Feeds neu laden",
create_all: "Alle erstellen",

//folder actions
mark_all_as_read: "Alle als gelesen markieren",

filtered_folders: "Gefilterte Ordner",
folders: "Ordner",
folder: "Ordner",
feeds: "Feeds",

//article actions
create_note: "Neue Notiz erstellen",
paste_to_note: "In aktuelle Notiz einfügen",
copy_to_clipboard: "In die Zwischenablage kopieren",
open_browser: "Im Webbrowser öffnen",
edit_tags: "Tags bearbeiten",
mark_as_read: "Als gelesen markieren",
mark_as_unread: "Als ungelesen markieren",
mark_as_favorite: "As Favorit markieren",
remove_from_favorites: "Aus den Favoriten entfernen",
read_article_tts: "Vorlesen",

mark_as_read_unread: "Als gelesen/ungelesen markieren",
mark_as_favorite_remove: "Als Favorit markieren/Aus den Favoriten entfernen",

//action notifications
marked_as_read: "Als gelesen markiert",
marked_as_unread: "Als ungelesen markiert",
removed_from_favorites: "Von den Favoriten entfernt",
added_to_favorites: "Als Favorit markiert",

//base modal
save: "Speichern",
cancel: "Abbrechen",
delete: "Löschen",
edit: "Bearbeiten",
reset: "zurücksetzen",
fix_errors: "Bitte behebe die Fehler vor dem speichern.",

add_new: "neu hinzufügen",

//feed settings
add_new_feed: "neuen Feed hinzufügen",
feed_already_configured: "Es existiert bereits ein Feed mit dieser URL",
no_folder: "Kein Ordner",

//feed creation modal
name: "Name",
name_help: "Unter welchem Namen soll dieser Feed angezeigt werden?",
url_help: "Wie lautet die URL zu diesem Feed?",
folder_help: "Als was kategorisierst du diesen Feed?",

invalid_name: "Du must einen gültigen Namen vergeben",
invalid_url: "diese URL ist nicht gültig",
invalid_feed: "Dieser Feed hat keine Einträge",

//filter types
filter_tags: "Alle Artikel mit Tags",
filter_unread: "Alle ungelesenen Artikel(aus Ordnern)",
filter_read: "Alle gelesenen Artikel(aus Ordnern)",
filter_favorites: "Favoriten(aus Ordnern)",

//sort order
sort_date_newest: 'Veröffentlichungsdatum (neu - alt)',
sort_date_oldest: 'Veröffentlichungsdatum (alt - neu)',
sort_alphabet_normal: 'Name (A - Z)',
sort_alphabet_inverted: 'Name (Z - A)',
sort: 'Ordnen nach',

//filter creation modal
filter_name_help: 'Wie soll der Filter angezeigt werden?',
filter_type: 'Typ',
filter_type_help: 'Typ des Filters',
filter: 'Filter',
filter_help: 'Order/Tags die gefiltert werden sollen, getrennt durch ,',

invalid_tag: "Dieser Tag ist nicht gültig",

note_exists: "Es existiert bereits eine Notiz mit diesem Namen",
invalid_filename: "Der Dateiname ist nicht gültig",

specify_name: "Bitte einen Dateinamen angeben",
cannot_contain: "kann nicht enhalten:",
created_note: "Notiz erstellt",
inserted_article: "in Notiz eingefügt",
no_file_active: "Keine Datei geöffnet",


//settings
settings: "Einstellungen",
file_creation: "Dateierstellung",
template_new: "Vorlage für neue Dateien",
template_new_help: "Beim erstellen einer Notiz wird dies verarbeitet.",
template_paste: "Vorlage beim Einfügen in eine Datei",
template_paste_help: "Beim einfügen/in die Zwischenablage kopieren wird dies verarbeitet.",
available_variables: "Mögliche Variablen sind:",
file_location: "Speicherort für neue Notizen",
file_location_help: "Wo sollen neue Notizen gespeichert werden?",
file_location_default: "In Standardordner",
file_location_custom: "Eigenen Ordner festlegen",
file_location_folder: "Ordner für neue Notizen",
file_location_folder_help: "Speichert neue Notizen an diesem Ort",

date_format: "Datumsformat",
syntax_reference: "Syntax Referenz",
syntax_looks: "So wird es aussehen: ",

ask_filename: "Nach Dateiname fragen",
ask_filename_help: "Deaktivieren um Titel als Dateinamen zu verwenden(ohne ungültige Zeichen)",
refresh_time: "Aktualisierungsintervall",
refresh_time_help: "Wie häufig soll auf neue Einträge überprüft werden(in Minuten), 0 zu deaktivieren",
specify_positive_number: "Bitte eine positive Zahl angeben",
multi_device_usage: "Mit mehreren Geräten nutzen",
multi_device_usage_help: "Syncronisiere Lesestatus & Tags zwischen mehreren gleichzeitig genutzten Geräten\n(Benötigt einen Neustart der App)",

add_new_filter: "Neuen gefilterten Ordner erstellen",
filter_exists: "Es exisitiert bereits ein Feed mit diesem Namen",
hotkeys: "Tastenkürzel",
hotkeys_reading: "in der Leseansicht",
}
Loading

0 comments on commit 123356b

Please sign in to comment.