🎨 Title localization when creating a document https://github.com/siyuan-note/siyuan/issues/10719

This commit is contained in:
Daniel 2024-03-24 22:15:19 +08:00
parent f5043a8c46
commit 2a8809bc7e
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
25 changed files with 72 additions and 61 deletions

View file

@ -1317,7 +1317,7 @@
"102": "Processing completed",
"103": "The update installation package has been automatically downloaded in the background. When exiting, you will be asked whether to install the new version",
"104": "The update installation package failed to download, please check the network connection",
"105": "TODO",
"105": "Untitled",
"106": "Maximum length is limited to 512 characters",
"107": "Moved document [%s]",
"108": "Data sync found conflicts, you can view the generated conflict content in [Data History]",

View file

@ -1317,7 +1317,7 @@
"102": "Procesamiento completado",
"103": "El paquete de instalación de la actualización se ha descargado automáticamente en segundo plano. Al salir, se le preguntará si desea instalar la nueva versión",
"104": "El paquete de instalación de la actualización no se pudo descargar, verifique la conexión de red",
"105": "TODO",
"105": "Sin título",
"106": "La longitud máxima está limitada a 512 caracteres",
"107": "Documento movido [%s]",
"108": "La sincronizaci\u00f3n de datos encontr\u00f3 en conflictos, puede ver el contenido del conflicto generado en [Historial de datos]",

View file

@ -1317,7 +1317,7 @@
"102": "Traitement terminé",
"103": "Le package d'installation de la mise à jour a été automatiquement téléchargé en arrière-plan. En quittant, il vous sera demandé si vous souhaitez installer la nouvelle version",
"104": "Le package d'installation de la mise à jour n'a pas pu être téléchargé, veuillez vérifier la connexion réseau",
"105": "TODO",
"105": "Sans titre",
"106": "La longueur maximale est limitée à 512 caractères",
"107": "Document déplacé [%s]",
"108": "La synchronisation des données a trouvé des conflits, vous pouvez afficher le contenu du conflit généré dans [Historique des données]",

View file

@ -648,7 +648,7 @@
"changeIcon": "修改圖示",
"randomIcon": "隨機圖標",
"includeSubFile": "\n包含 x 個子文檔",
"untitled": "新文檔",
"untitled": "未命名",
"lockScreen": "鎖定畫面",
"cloudIntro1": "端到端加密資料同步",
"cloudIntro2": "加密和解密過程完全在本地設備上進行",
@ -1317,7 +1317,7 @@
"102": "處理完畢",
"103": "已經在後台開始自動下載更新安裝檔,退出時將詢問是否安裝新版本",
"104": "更新安裝檔下載失敗,請檢查網絡連接",
"105": "TODO",
"105": "未命名",
"106": "最大長度限制為 512 字元",
"107": "已經移動文檔 [%s]",
"108": "資料同步發現衝突,可在 [資料歷史] 中查看生成的衝突內容",

View file

@ -648,7 +648,7 @@
"changeIcon": "修改图标",
"randomIcon": "随机图标",
"includeSubFile": "\n包含 x 个子文档",
"untitled": "新文档",
"untitled": "未命名",
"lockScreen": "锁屏",
"cloudIntro1": "端到端加密数据同步",
"cloudIntro2": "加密和解密过程完全在本地设备上进行",
@ -1317,7 +1317,7 @@
"102": "处理完毕",
"103": "已经在后台开始自动下载更新安装包,退出时将询问是否安装新版本",
"104": "更新安装包下载失败,请检查网络连接",
"105": "TODO",
"105": "未命名",
"106": "最大长度限制为 512 字符",
"107": "已经移动文档 [%s]",
"108": "数据同步发现冲突,可在 [数据历史] 中查看生成的冲突内容",

View file

@ -18,8 +18,7 @@ import {newFile} from "../../util/newFile";
import {Constants} from "../../constants";
import {openSetting} from "../../config";
import {getInstanceById} from "../../layout/util";
import {closeTabByType, copyTab, getDockByType, resizeTabs, switchTabByIndex} from "../../layout/tabUtil";
import {getActiveTab} from "../../layout/tabUtil";
import {closeTabByType, copyTab, getActiveTab, getDockByType, resizeTabs, switchTabByIndex} from "../../layout/tabUtil";
import {Tab} from "../../layout/Tab";
import {Editor} from "../../editor";
import {setEditMode} from "../../protyle/util/setEditMode";
@ -369,7 +368,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
}
if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.spaceRepetition.custom, event)) {
fetchPost("/api/riff/getTreeRiffDueCards", {rootID: protyle.block.rootID}, (response) => {
openCardByData(app, response.data, "doc", protyle.block.rootID, protyle.title.editElement.textContent || "Untitled");
openCardByData(app, response.data, "doc", protyle.block.rootID, protyle.title.editElement.textContent || window.siyuan.languages.untitled);
});
event.preventDefault();
return true;
@ -428,7 +427,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null,
title: protyle.title ? (protyle.title.editElement.textContent || window.siyuan.languages.untitled) : null,
});
return true;
}
@ -449,7 +448,7 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null,
title: protyle.title ? (protyle.title.editElement.textContent || window.siyuan.languages.untitled) : null,
});
return true;
}

View file

@ -54,7 +54,7 @@ export const reloadSync = (app: App, data: { upsertRootIDs: string[], removeRoot
id: window.siyuan.mobile.editor.protyle.block.rootID
}, (response) => {
setTitle(response.data.name);
(document.getElementById("toolbarName") as HTMLInputElement).value = response.data.name === "Untitled" ? "" : response.data.name;
(document.getElementById("toolbarName") as HTMLInputElement).value = response.data.name === window.siyuan.languages.untitled ? "" : response.data.name;
});
}
}
@ -389,7 +389,7 @@ export const setTitle = (title: string) => {
dragElement.setAttribute("title", versionTitle);
}
} else {
title = title || "Untitled";
title = title || window.siyuan.languages.untitled;
document.title = `${title} - ${workspaceName} - ${window.siyuan.languages.siyuanNote} v${Constants.SIYUAN_VERSION}`;
if (!dragElement) {
return;

View file

@ -82,7 +82,7 @@ export const rename = (options: {
return false;
}
if (inputElement.value.trim() === "") {
inputElement.value = "Untitled";
inputElement.value = window.siyuan.languages.untitled;
} else {
inputElement.value = replaceFileName(inputElement.value);
}

View file

@ -40,13 +40,13 @@ export const openBacklink = async (options: {
}
options.rootId = response.data.rootID;
options.useBlockId = response.data.rootID !== response.data.id;
options.title = response.data.name || "Untitled";
options.title = response.data.name || window.siyuan.languages.untitled;
} else if (!options.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
if (response.code === -1) {
return;
}
options.title = response.data.name || "Untitled";
options.title = response.data.name || window.siyuan.languages.untitled;
}
const newWnd = wnd.split("lr");
newWnd.addTab(new Tab({
@ -96,13 +96,13 @@ export const openGraph = async (options: {
}
options.rootId = response.data.rootID;
options.useBlockId = response.data.rootID !== response.data.id;
options.title = response.data.name || "Untitled";
options.title = response.data.name || window.siyuan.languages.untitled;
} else if (!options.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: options.blockId});
if (response.code === -1) {
return;
}
options.title = response.data.name || "Untitled";
options.title = response.data.name || window.siyuan.languages.untitled;
}
const newWnd = wnd.split("lr");
newWnd.addTab(new Tab({
@ -142,9 +142,9 @@ export const openOutline = async (protyle: IProtyle) => {
let title = "";
if (!protyle.title) {
const response = await fetchSyncPost("api/block/getDocInfo", {id: protyle.block.rootID});
title = response.data.name || "Untitled";
title = response.data.name || window.siyuan.languages.untitled;
} else {
title = protyle.title.editElement.textContent || "Untitled";
title = protyle.title.editElement.textContent || window.siyuan.languages.untitled;
}
newWnd.addTab(new Tab({
icon: "iconAlignCenter",

View file

@ -476,7 +476,7 @@ export const exportMd = (id: string) => {
});
btnsElement[1].addEventListener("click", () => {
if (inputElement.value.trim() === "") {
inputElement.value = "Untitled";
inputElement.value = window.siyuan.languages.untitled;
} else {
inputElement.value = replaceFileName(inputElement.value);
}

View file

@ -91,7 +91,7 @@ export const openMobileFileById = (app: App, id: string, action = [Constants.CB_
} else {
window.siyuan.mobile.editor = new Protyle(app, document.getElementById("editor"), protyleOptions);
}
(document.getElementById("toolbarName") as HTMLInputElement).value = data.data.rootTitle === "Untitled" ? "" : data.data.rootTitle;
(document.getElementById("toolbarName") as HTMLInputElement).value = data.data.rootTitle === window.siyuan.languages.untitled ? "" : data.data.rootTitle;
setEditor();
closePanel();
});

View file

@ -44,7 +44,7 @@ const focusStack = (backStack: IBackStack) => {
id: backStack.id,
}, (response) => {
setTitle(response.data.name);
(document.getElementById("toolbarName") as HTMLInputElement).value = response.data.name === "Untitled" ? "" : response.data.name;
(document.getElementById("toolbarName") as HTMLInputElement).value = response.data.name === window.siyuan.languages.untitled ? "" : response.data.name;
protyle.background.render(response.data.ial, protyle.block.rootID);
protyle.wysiwyg.renderCustom(response.data.ial);
});

View file

@ -1,14 +1,15 @@
import {
focusBlock, focusByOffset,
focusByRange, focusByWbr,
getEditorRange, getSelectionOffset,
focusBlock,
focusByOffset,
focusByRange,
focusByWbr,
getEditorRange,
getSelectionOffset,
} from "../util/selection";
import {fetchPost} from "../../util/fetch";
import {replaceFileName, validateName} from "../../editor/rename";
import {MenuItem} from "../../menus/Menu";
import {
openFileAttr,
} from "../../menus/commonMenuItem";
import {openFileAttr,} from "../../menus/commonMenuItem";
import {Constants} from "../../constants";
import {matchHotKey} from "../util/hotKey";
import {isMac, readText, writeText} from "../util/compatibility";
@ -264,7 +265,7 @@ export class Title {
public setTitle(title: string) {
if (code160to32(title) !== code160to32(this.editElement.textContent)) {
this.editElement.textContent = title === "Untitled" ? "" : title;
this.editElement.textContent = title === window.siyuan.languages.untitled ? "" : title;
}
}

View file

@ -1,12 +1,6 @@
import {fetchPost, fetchSyncPost} from "../../util/fetch";
import {MenuItem} from "../../menus/Menu";
import {
copySubMenu,
exportMd,
movePathToMenu,
openFileAttr,
openFileWechatNotify,
} from "../../menus/commonMenuItem";
import {copySubMenu, exportMd, movePathToMenu, openFileAttr, openFileWechatNotify,} from "../../menus/commonMenuItem";
import {deleteFile} from "../../editor/deleteFile";
import {updateHotkeyTip} from "../util/compatibility";
/// #if !MOBILE
@ -105,7 +99,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null
title: protyle.title ? (protyle.title.editElement.textContent || window.siyuan.languages.untitled) : null
});
}
}).element);
@ -119,7 +113,7 @@ export const openTitleMenu = (protyle: IProtyle, position: IPosition) => {
blockId: protyle.block.id,
rootId: protyle.block.rootID,
useBlockId: protyle.block.showAll,
title: protyle.title ? (protyle.title.editElement.textContent || "Untitled") : null
title: protyle.title ? (protyle.title.editElement.textContent || window.siyuan.languages.untitled) : null
});
}
}).element);

View file

@ -619,7 +619,7 @@ ${genHintItemHTML(item)}
fetchPost("/api/filetree/createDoc", {
notebook: protyle.notebookId,
path: pathPosix().join(getDisplayName(protyle.path, false, true), newSubDocId + ".sy"),
title: "Untitled",
title: window.siyuan.languages.untitled,
md: ""
}, () => {
insertHTML(`<span data-type="block-ref" data-id="${newSubDocId}" data-subtype="d">Untitled</span>`, protyle);

View file

@ -13,9 +13,9 @@ const genAVRollupHTML = (value: IAVCellValue) => {
switch (value.type) {
case "block":
if (value?.isDetached) {
html = `<span data-id="${value.block?.id}">${value.block?.content || "Untitled"}</span>`;
html = `<span data-id="${value.block?.id}">${value.block?.content || window.siyuan.languages.untitled}</span>`;
} else {
html = `<span data-type="block-ref" data-id="${value.block?.id}" data-subtype="s" class="av__celltext--ref">${value.block?.content || "Untitled"}</span>`;
html = `<span data-type="block-ref" data-id="${value.block?.id}" data-subtype="s" class="av__celltext--ref">${value.block?.content || window.siyuan.languages.untitled}</span>`;
}
break;
case "text":

View file

@ -613,7 +613,7 @@ export const renderCell = (cellValue: IAVCellValue) => {
text = `<span class="av__celltext">${cellValue.block.content || ""}</span>
<span class="b3-chip b3-chip--info b3-chip--small" data-type="block-more">${window.siyuan.languages.more}</span>`;
} else {
text = `<span data-type="block-ref" data-id="${cellValue.block.id}" data-subtype="s" class="av__celltext av__celltext--ref">${cellValue.block.content || "Untitled"}</span>
text = `<span data-type="block-ref" data-id="${cellValue.block.id}" data-subtype="s" class="av__celltext av__celltext--ref">${cellValue.block.content || window.siyuan.languages.untitled}</span>
<span class="b3-chip b3-chip--info b3-chip--small" data-type="block-more">${window.siyuan.languages.update}</span>`;
}
} else if (cellValue.type === "number") {
@ -691,9 +691,9 @@ const renderRollup = (cellValue: IAVCellValue) => {
}
} else if (cellValue.type === "block") {
if (cellValue?.isDetached) {
text = `<span class="av__celltext" data-id="${cellValue.block?.id}">${cellValue.block?.content || "Untitled"}</span>`;
text = `<span class="av__celltext" data-id="${cellValue.block?.id}">${cellValue.block?.content || window.siyuan.languages.untitled}</span>`;
} else {
text = `<span data-type="block-ref" data-id="${cellValue.block?.id}" data-subtype="s" class="av__celltext av__celltext--ref">${cellValue.block?.content || "Untitled"}</span>`;
text = `<span data-type="block-ref" data-id="${cellValue.block?.id}" data-subtype="s" class="av__celltext av__celltext--ref">${cellValue.block?.content || window.siyuan.languages.untitled}</span>`;
}
} else if (cellValue.type === "number") {
text = cellValue?.number.formattedContent || cellValue?.number.content.toString() || "";

View file

@ -240,11 +240,11 @@ const filterItem = (menuElement: Element, cellElement: HTMLElement, keyword: str
const hasIds: string[] = [];
cellElement.querySelectorAll("span").forEach((item) => {
hasIds.push(item.dataset.id);
selectHTML += `<button data-id="${item.dataset.id}" data-type="setRelationCell" class="b3-menu__item${item.textContent.indexOf(keyword) > -1 ? "" : " fn__none"}" draggable="true">${genSelectItemHTML("selected", item.dataset.id, !item.classList.contains("av__celltext--ref"), item.textContent || "Untitled")}</button>`;
selectHTML += `<button data-id="${item.dataset.id}" data-type="setRelationCell" class="b3-menu__item${item.textContent.indexOf(keyword) > -1 ? "" : " fn__none"}" draggable="true">${genSelectItemHTML("selected", item.dataset.id, !item.classList.contains("av__celltext--ref"), item.textContent || window.siyuan.languages.untitled)}</button>`;
});
cells.forEach((item) => {
if (!hasIds.includes(item.block.id)) {
html += genSelectItemHTML("unselect", item.block.id, item.isDetached, item.block.content || "Untitled");
html += genSelectItemHTML("unselect", item.block.id, item.isDetached, item.block.content || window.siyuan.languages.untitled);
}
});
menuElement.querySelector(".b3-menu__items").innerHTML = `${selectHTML || genSelectItemHTML("empty")}
@ -270,11 +270,11 @@ export const bindRelationEvent = (options: {
const hasIds: string[] = [];
options.cellElements[0].querySelectorAll("span").forEach((item) => {
hasIds.push(item.dataset.id);
selectHTML += `<button data-id="${item.dataset.id}" data-type="setRelationCell" class="b3-menu__item" draggable="true">${genSelectItemHTML("selected", item.dataset.id, !item.classList.contains("av__celltext--ref"), item.textContent || "Untitled")}</button>`;
selectHTML += `<button data-id="${item.dataset.id}" data-type="setRelationCell" class="b3-menu__item" draggable="true">${genSelectItemHTML("selected", item.dataset.id, !item.classList.contains("av__celltext--ref"), item.textContent || window.siyuan.languages.untitled)}</button>`;
});
cells.forEach((item) => {
if (!hasIds.includes(item.block.id)) {
html += genSelectItemHTML("unselect", item.block.id, item.isDetached, item.block.content || "Untitled");
html += genSelectItemHTML("unselect", item.block.id, item.isDetached, item.block.content || window.siyuan.languages.untitled);
}
});
options.menuElement.querySelector(".b3-menu__label").innerHTML = response.data.name;

View file

@ -96,7 +96,7 @@ export const newFile = (optios: {
if (data.data.path.startsWith("/") || optios.currentPath === "/") {
fetchPost("/api/filetree/createDocWithMd", {
notebook: optios.notebookId,
path: pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? "Untitled" : "")),
path: pathPosix().join(data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")),
// 根目录时无法确定 parentID
markdown: ""
}, response => {
@ -117,7 +117,7 @@ export const newFile = (optios: {
}, (responseHPath) => {
fetchPost("/api/filetree/createDocWithMd", {
notebook: optios.notebookId,
path: pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? "Untitled" : "")),
path: pathPosix().join(responseHPath.data, data.data.path, optios.name || (data.data.path.endsWith("/") ? window.siyuan.languages.untitled : "")),
parentID: getDisplayName(optios.currentPath, true, true),
markdown: ""
}, response => {
@ -134,7 +134,7 @@ export const newFile = (optios: {
});
}
} else {
const title = pathPosix().basename(data.data.path || "Untitled");
const title = pathPosix().basename(data.data.path || window.siyuan.languages.untitled);
if (!validateName(title)) {
return;
}
@ -191,12 +191,12 @@ export const newFileByName = (app: App, value: string) => {
newFile({
app,
useSavePath: true,
name: replaceFileName(value.trim()) || "Untitled"
name: replaceFileName(value.trim()) || window.siyuan.languages.untitled
});
};
export const newFileBySelect = (protyle: IProtyle, selectText: string, nodeElement: HTMLElement, pathDir: string) => {
const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML).replace(/\n/g, "")) || "Untitled";
const newFileName = replaceFileName(selectText.trim() ? selectText.trim() : protyle.lute.BlockDOM2Content(nodeElement.outerHTML).replace(/\n/g, "")) || window.siyuan.languages.untitled;
const hPath = pathPosix().join(pathDir, newFileName);
fetchPost("/api/filetree/getIDsByHPath", {
path: hPath,

View file

@ -1738,7 +1738,7 @@ func getAvNames(avIDs string) (ret string) {
continue
}
if "" == nodeAvName {
nodeAvName = "Untitled"
nodeAvName = Conf.language(105)
}
tpl := strings.ReplaceAll(attrAvNameTpl, "${avID}", nodeAvID)

View file

@ -101,7 +101,7 @@ func GetDocInfo(blockID string) (ret *BlockInfo) {
}
if "" == avName {
avName = "Untitled"
avName = Conf.language(105)
}
attrView := &AttrView{ID: avID, Name: avName}

View file

@ -76,7 +76,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
name := util.FilterFileName(attrView.Name)
if "" == name {
name = "Untitled"
name = Conf.language(105)
}
table, err := renderAttributeViewTable(attrView, view, "")
@ -1375,7 +1375,7 @@ func BatchExportMarkdown(boxID, folderPath string) (zipPath string) {
baseFolderName = path.Base(block.HPath)
}
if "" == baseFolderName {
baseFolderName = "Untitled"
baseFolderName = Conf.language(105)
}
docFiles := box.ListFiles(folderPath)

View file

@ -1568,7 +1568,7 @@ func RenameDoc(boxID, p, title string) (err error) {
return
}
if "" == title {
title = "Untitled"
title = Conf.language(105)
}
title = strings.ReplaceAll(title, "/", "")
@ -1604,6 +1604,10 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {
return
}
title = strings.ReplaceAll(title, "/", "")
title = strings.TrimSpace(title)
if "" == title {
title = Conf.Language(105)
}
baseName := strings.TrimSpace(path.Base(p))
if "" == strings.TrimSuffix(baseName, ".sy") {

View file

@ -687,7 +687,7 @@ func indexHistoryDir(name string, luteEngine *lute.Lute) {
title := tree.Root.IALAttr("title")
if "" == title {
title = "Untitled"
title = Conf.language(105)
}
content := tree.Root.Content()
p := strings.TrimPrefix(doc, util.HistoryDir)

View file

@ -40,6 +40,9 @@ func CreateBox(name string) (id string, err error) {
err = errors.New(Conf.Language(106))
return
}
if "" == name {
name = Conf.language(105)
}
WaitForWritingFiles()
@ -67,6 +70,16 @@ func RenameBox(boxID, name string) (err error) {
return errors.New(Conf.Language(0))
}
if 512 < utf8.RuneCountInString(name) {
// 限制笔记本名和文档名最大长度为 `512`
err = errors.New(Conf.Language(106))
return
}
if "" == name {
name = Conf.language(105)
}
boxConf := box.GetConf()
boxConf.Name = name
box.Name = name