mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 19:12:27 +08:00
feat(i18n): restore hidden subtree names on language change
This commit is contained in:
parent
6a9865eb4f
commit
690506ea26
@ -272,17 +272,21 @@ const HIDDEN_SUBTREE_DEFINITION: Item = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
function checkHiddenSubtree(force = false) {
|
interface CheckHiddenExtraOpts {
|
||||||
|
restoreNames?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkHiddenSubtree(force = false, extraOpts: CheckHiddenExtraOpts = {}) {
|
||||||
if (!force && !migrationService.isDbUpToDate()) {
|
if (!force && !migrationService.isDbUpToDate()) {
|
||||||
// on-delete hook might get triggered during some future migration and cause havoc
|
// on-delete hook might get triggered during some future migration and cause havoc
|
||||||
log.info("Will not check hidden subtree until migration is finished.");
|
log.info("Will not check hidden subtree until migration is finished.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkHiddenSubtreeRecursively('root', HIDDEN_SUBTREE_DEFINITION);
|
checkHiddenSubtreeRecursively('root', HIDDEN_SUBTREE_DEFINITION, extraOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkHiddenSubtreeRecursively(parentNoteId: string, item: Item) {
|
function checkHiddenSubtreeRecursively(parentNoteId: string, item: Item, extraOpts: CheckHiddenExtraOpts = {}) {
|
||||||
if (!item.id || !item.type || !item.title) {
|
if (!item.id || !item.type || !item.title) {
|
||||||
throw new Error(`Item does not contain mandatory properties: ${JSON.stringify(item)}`);
|
throw new Error(`Item does not contain mandatory properties: ${JSON.stringify(item)}`);
|
||||||
}
|
}
|
||||||
@ -335,6 +339,11 @@ function checkHiddenSubtreeRecursively(parentNoteId: string, item: Item) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (extraOpts.restoreNames && note.title !== item.title) {
|
||||||
|
note.title = item.title;
|
||||||
|
note.save();
|
||||||
|
}
|
||||||
|
|
||||||
if (note.type !== item.type) {
|
if (note.type !== item.type) {
|
||||||
// enforce a correct note type
|
// enforce a correct note type
|
||||||
note.type = item.type;
|
note.type = item.type;
|
||||||
@ -371,7 +380,7 @@ function checkHiddenSubtreeRecursively(parentNoteId: string, item: Item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const child of item.children || []) {
|
for (const child of item.children || []) {
|
||||||
checkHiddenSubtreeRecursively(item.id, child);
|
checkHiddenSubtreeRecursively(item.id, child, extraOpts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import options from "./options.js";
|
|||||||
import sql_init from "./sql_init.js";
|
import sql_init from "./sql_init.js";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
import { getResourceDir } from "./utils.js";
|
import { getResourceDir } from "./utils.js";
|
||||||
|
import hidden_subtree from "./hidden_subtree.js";
|
||||||
|
|
||||||
export async function initializeTranslations() {
|
export async function initializeTranslations() {
|
||||||
const resourceDir = getResourceDir();
|
const resourceDir = getResourceDir();
|
||||||
@ -33,6 +34,7 @@ function getCurrentLanguage() {
|
|||||||
return language;
|
return language;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function changeLanguage(locale: string) {
|
export async function changeLanguage(locale: string) {
|
||||||
return i18next.changeLanguage(locale);
|
await i18next.changeLanguage(locale);
|
||||||
|
hidden_subtree.checkHiddenSubtree(true, { restoreNames: true });
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user