web: localize

This commit is contained in:
Ammar Ahmed
2024-09-06 11:07:43 +05:00
committed by Abdullah Atta
parent bb1ec22197
commit e78b245eea
11 changed files with 1219 additions and 501 deletions

View File

@@ -200,25 +200,6 @@
"node": ">=10" "node": ">=10"
} }
}, },
"node_modules/@electron/notarize/node_modules/jsonfile": {
"version": "6.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"universalify": "^2.0.0"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
},
"node_modules/@electron/notarize/node_modules/universalify": {
"version": "2.0.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 10.0.0"
}
},
"node_modules/@electron/osx-sign": { "node_modules/@electron/osx-sign": {
"version": "1.3.1", "version": "1.3.1",
"resolved": "https://registry.npmjs.org/@electron/osx-sign/-/osx-sign-1.3.1.tgz", "resolved": "https://registry.npmjs.org/@electron/osx-sign/-/osx-sign-1.3.1.tgz",
@@ -315,17 +296,6 @@
"node": ">=14.14" "node": ">=14.14"
} }
}, },
"node_modules/@electron/universal/node_modules/jsonfile": {
"version": "6.1.0",
"dev": true,
"license": "MIT",
"dependencies": {
"universalify": "^2.0.0"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
},
"node_modules/@electron/universal/node_modules/minimatch": { "node_modules/@electron/universal/node_modules/minimatch": {
"version": "9.0.5", "version": "9.0.5",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
@@ -342,14 +312,6 @@
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/@electron/universal/node_modules/universalify": {
"version": "2.0.1",
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 10.0.0"
}
},
"node_modules/@esbuild/aix-ppc64": { "node_modules/@esbuild/aix-ppc64": {
"version": "0.24.0", "version": "0.24.0",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.0.tgz", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.0.tgz",
@@ -1396,6 +1358,11 @@
"file-uri-to-path": "1.0.0" "file-uri-to-path": "1.0.0"
} }
}, },
"node_modules/bindings/node_modules/file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw=="
},
"node_modules/bl": { "node_modules/bl": {
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz",
@@ -1475,6 +1442,25 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/buffer/node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/builder-util": { "node_modules/builder-util": {
"version": "25.0.3", "version": "25.0.3",
"resolved": "https://registry.npmjs.org/builder-util/-/builder-util-25.0.3.tgz", "resolved": "https://registry.npmjs.org/builder-util/-/builder-util-25.0.3.tgz",
@@ -4420,6 +4406,25 @@
"url": "https://github.com/sponsors/Borewit" "url": "https://github.com/sponsors/Borewit"
} }
}, },
"node_modules/token-types/node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
]
},
"node_modules/tree-kill": { "node_modules/tree-kill": {
"version": "1.2.2", "version": "1.2.2",
"resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz", "resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz",
@@ -4541,7 +4546,7 @@
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">= 4.0.0" "node": ">= 10.0.0"
} }
}, },
"node_modules/utf8-byte-length": { "node_modules/utf8-byte-length": {

View File

@@ -27,6 +27,7 @@ import { showFilePicker } from "../../utils/file-picker";
import { Attachment } from "@notesnook/editor"; import { Attachment } from "@notesnook/editor";
import { ImagePickerDialog } from "../../dialogs/image-picker-dialog"; import { ImagePickerDialog } from "../../dialogs/image-picker-dialog";
import { BuyDialog } from "../../dialogs/buy-dialog"; import { BuyDialog } from "../../dialogs/buy-dialog";
import { strings } from "@notesnook/intl";
const FILE_SIZE_LIMIT = 500 * 1024 * 1024; const FILE_SIZE_LIMIT = 500 * 1024 * 1024;
const IMAGE_SIZE_LIMIT = 50 * 1024 * 1024; const IMAGE_SIZE_LIMIT = 50 * 1024 * 1024;
@@ -104,8 +105,7 @@ async function pickFile(
): Promise<Attachment | undefined> { ): Promise<Attachment | undefined> {
try { try {
if (file.size > FILE_SIZE_LIMIT) if (file.size > FILE_SIZE_LIMIT)
throw new Error("File too big. You cannot add files over 500 MB."); throw new Error(strings.fileTooLargeDesc(500));
if (!file) return;
const hash = await addAttachment(file, options); const hash = await addAttachment(file, options);
return { return {
@@ -131,7 +131,7 @@ async function pickImage(
): Promise<Attachment | undefined> { ): Promise<Attachment | undefined> {
try { try {
if (file.size > IMAGE_SIZE_LIMIT) if (file.size > IMAGE_SIZE_LIMIT)
throw new Error("Image too big. You cannot add images over 50 MB."); throw new Error(strings.imageTooLarge(50));
if (!file) return; if (!file) return;
const hash = await addAttachment(file, options); const hash = await addAttachment(file, options);

View File

@@ -374,10 +374,9 @@ const menuItems: (
onClick: async () => { onClick: async () => {
const { unlock, lock } = store.get(); const { unlock, lock } = store.get();
if (!context?.locked) { if (!context?.locked) {
if (await lock(note.id)) if (await lock(note.id)) showToast("success", strings.noteLocked());
showToast("success", "Note locked successfully!");
} else if (await unlock(note.id)) { } else if (await unlock(note.id)) {
showToast("success", "Note unlocked successfully!"); showToast("success", strings.noteUnlocked());
} }
} }
}, },
@@ -827,9 +826,9 @@ async function copyNote(noteId: string, format: "md" | "txt") {
if (!result) throw new Error(`Could not convert note to ${format}.`); if (!result) throw new Error(`Could not convert note to ${format}.`);
await navigator.clipboard.writeText(result); await navigator.clipboard.writeText(result);
showToast("success", "Copied!"); showToast("success", strings.noteCopied());
} catch (e) { } catch (e) {
if (e instanceof Error) if (e instanceof Error)
showToast("error", `Failed to copy note: ${e.message}.`); showToast("error", `${strings.failedToCopyNote()}: ${e.message}.`);
} }
} }

View File

@@ -203,12 +203,14 @@ function PublishView(props: PublishViewProps) {
password password
}); });
setPublishId(publishId); setPublishId(publishId);
showToast("success", strings.notePublished()); showToast("success", strings.action("note", 1, "published"));
} catch (e) { } catch (e) {
console.error(e); console.error(e);
showToast( showToast(
"error", "error",
`${strings.failedToPublish()}: ${(e as Error).message}` `${strings.actionError("note", 1, "published")}: ${
(e as Error).message
}`
); );
} finally { } finally {
setIsPublishing(false); setIsPublishing(false);
@@ -226,12 +228,13 @@ function PublishView(props: PublishViewProps) {
await unpublishNote(note.id); await unpublishNote(note.id);
setPublishId(undefined); setPublishId(undefined);
onClose(true); onClose(true);
showToast("success", "Note unpublished."); showToast("success", strings.action("note", 1, "unpublished"));
} catch (e) { } catch (e) {
console.error(e); console.error(e);
showToast( showToast(
"error", "error",
"Note could not be unpublished: " + (e as Error).message `${strings.actionError("note", 1, "unpublished")}: ` +
(e as Error).message
); );
} finally { } finally {
setIsPublishing(false); setIsPublishing(false);

View File

@@ -29,6 +29,7 @@ import { handleDrop } from "../../common/drop-handler";
import { EditTagDialog } from "../../dialogs/item-dialog"; import { EditTagDialog } from "../../dialogs/item-dialog";
import { useStore as useSelectionStore } from "../../stores/selection-store"; import { useStore as useSelectionStore } from "../../stores/selection-store";
import { Multiselect } from "../../common/multi-select"; import { Multiselect } from "../../common/multi-select";
import { strings } from "@notesnook/intl";
type TagProps = { item: TagType; totalNotes: number }; type TagProps = { item: TagType; totalNotes: number };
function Tag(props: TagProps) { function Tag(props: TagProps) {
@@ -80,7 +81,7 @@ const menuItems: (tag: TagType, ids?: string[]) => MenuItem[] = (
{ {
type: "button", type: "button",
key: "edit", key: "edit",
title: "Rename tag", title: strings.renameTag(),
icon: Edit.path, icon: Edit.path,
onClick: () => EditTagDialog.show(tag) onClick: () => EditTagDialog.show(tag)
}, },
@@ -88,8 +89,8 @@ const menuItems: (tag: TagType, ids?: string[]) => MenuItem[] = (
type: "button", type: "button",
key: "shortcut", key: "shortcut",
title: db.shortcuts.exists(tag.id) title: db.shortcuts.exists(tag.id)
? "Remove shortcut" ? strings.removeShortcut()
: "Create shortcut", : strings.addShortcut(),
icon: Shortcut.path, icon: Shortcut.path,
onClick: () => appStore.addToShortcuts(tag) onClick: () => appStore.addToShortcuts(tag)
}, },

View File

@@ -51,7 +51,7 @@ export function UnlockView(props: UnlockViewProps) {
) { ) {
setIsWrong(true); setIsWrong(true);
} else { } else {
showToast("error", "Could not unlock: " + e); showToast("error", `${strings.couldNotUnlock()}: ` + e);
console.error(e); console.error(e);
} }
} finally { } finally {

View File

@@ -43,7 +43,7 @@ export const AddNotebookDialog = DialogManager.register(
const onSubmit = useCallback(async () => { const onSubmit = useCallback(async () => {
if (!title.current.trim()) if (!title.current.trim())
return showToast("error", "Notebook title cannot be empty."); return showToast("error", strings.allFieldsRequired());
const id = await db.notebooks.add({ const id = await db.notebooks.add({
id: props.notebook?.id, id: props.notebook?.id,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -18,6 +18,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
import { I18n } from "@lingui/core"; import { I18n } from "@lingui/core";
import { plural, select, t } from "@lingui/macro"; import { plural, select, t } from "@lingui/macro";
type Actions =
| "deleted"
| "unpinned"
| "pinned"
| "unpublished"
| "published"
| "permanentlyDeleted";
export const strings = { export const strings = {
done: () => t`Done`, done: () => t`Done`,
@@ -254,7 +261,8 @@ export const strings = {
tag: () => t`tag`, tag: () => t`tag`,
reminder: () => t`reminder`, reminder: () => t`reminder`,
color: () => t`color`, color: () => t`color`,
attachment: () => t`attachment` attachment: () => t`attachment`,
item: () => t`item`
}, },
dataTypesCamelCase: { dataTypesCamelCase: {
note: () => t`Note`, note: () => t`Note`,
@@ -262,7 +270,8 @@ export const strings = {
tag: () => t`Tag`, tag: () => t`Tag`,
reminder: () => t`Reminder`, reminder: () => t`Reminder`,
color: () => t`Color`, color: () => t`Color`,
attachment: () => t`Attachment` attachment: () => t`Attachment`,
item: () => t`Item`
}, },
dataTypesPlural: { dataTypesPlural: {
note: () => t`notes`, note: () => t`notes`,
@@ -270,7 +279,8 @@ export const strings = {
tag: () => t`tags`, tag: () => t`tags`,
reminder: () => t`reminders`, reminder: () => t`reminders`,
color: () => t`colors`, color: () => t`colors`,
attachment: () => t`attachments` attachment: () => t`attachments`,
item: () => t`items`
}, },
dataTypesPluralCamelCase: { dataTypesPluralCamelCase: {
note: () => t`Notes`, note: () => t`Notes`,
@@ -280,7 +290,8 @@ export const strings = {
color: () => t`Colors`, color: () => t`Colors`,
attachment: () => t`Attachments`, attachment: () => t`Attachments`,
favorite: () => t`Favorites`, favorite: () => t`Favorites`,
monograph: () => t`Monographs` monograph: () => t`Monographs`,
item: () => t`Items`
}, },
addItem: (referenceType: string) => addItem: (referenceType: string) =>
t`Add a ${strings.dataTypes[ t`Add a ${strings.dataTypes[
@@ -477,6 +488,7 @@ $headline$: Use starting line of the note as title.`,
useAccountPassword: () => t`Use account password`, useAccountPassword: () => t`Use account password`,
addColor: () => t`Add color`, addColor: () => t`Add color`,
unlockNote: () => t`Unlock note`, unlockNote: () => t`Unlock note`,
couldNotUnlock: () => t`Could not unlock`,
unlockNoteDesc: () => unlockNoteDesc: () =>
t`"Your note will be unencrypted and removed from the vault."`, t`"Your note will be unencrypted and removed from the vault."`,
deleteAllNotes: () => t`Delete all notes`, deleteAllNotes: () => t`Delete all notes`,
@@ -840,9 +852,11 @@ $headline$: Use starting line of the note as title.`,
encryptingAttachment: () => t`Encrypting attachment`, encryptingAttachment: () => t`Encrypting attachment`,
encryptingAttachmentDesc: (name: string) => encryptingAttachmentDesc: (name: string) =>
t`Please wait while we encrypt ${name} for upload.`, t`Please wait while we encrypt ${name} for upload.`,
fileTooLarge: () => t`File too large`, fileTooLarge: () => t`File too big`,
fileTooLargeDesc: (sizeInMB: number) => fileTooLargeDesc: (sizeInMB: number) =>
t`File size should be less than ${sizeInMB}MB`, t`File size should be less than ${sizeInMB}MB`,
imageTooLarge: (sizeInMB: number) =>
t`Image size should be less than ${sizeInMB}MB`,
failToOpen: () => t`Failed to open`, failToOpen: () => t`Failed to open`,
fileMismatch: () => t`File mismatch`, fileMismatch: () => t`File mismatch`,
noNoteProperties: () => t`Start writing to create a new note`, noNoteProperties: () => t`Start writing to create a new note`,
@@ -1789,11 +1803,16 @@ All attachments will be downloaded & cached again on access.
strings.dataTypesPlural[type as keyof typeof strings.dataTypesPlural] strings.dataTypesPlural[type as keyof typeof strings.dataTypesPlural]
} moved to trash` } moved to trash`
}), }),
action: (type: string, count: number, action: "deleted" | "unpinned") => { actions: () => ({
const actions: { [name: string]: any } = { deleted: t`deleted`,
deleted: t`deleted`, unpinned: t`unpinned`,
unpinned: t`unpinned` pinned: t`pinned`,
}; unpublished: t`unpublished`,
published: t`published`,
permanentlyDeleted: t`permanently deleted`
}),
action: (type: string, count: number, action: Actions) => {
const actions = strings.actions();
return plural(count, { return plural(count, {
one: `${ one: `${
strings.dataTypesCamelCase[type as keyof typeof strings.dataTypes] strings.dataTypesCamelCase[type as keyof typeof strings.dataTypes]
@@ -1803,6 +1822,17 @@ All attachments will be downloaded & cached again on access.
} ${actions[action]}` } ${actions[action]}`
}); });
}, },
actionError: (type: string, count: number, action: Actions) => {
const actions = strings.actions();
return plural(count, {
one: `${
strings.dataTypesCamelCase[type as keyof typeof strings.dataTypes]
} could not be ${actions[action]}`,
other: `# ${
strings.dataTypesPlural[type as keyof typeof strings.dataTypesPlural]
} could not be ${actions[action]}`
});
},
deleted: (type: string, count: number) => deleted: (type: string, count: number) =>
plural(count, { plural(count, {
one: `${ one: `${
@@ -1842,5 +1872,6 @@ All attachments will be downloaded & cached again on access.
backupReadyToDownload: () => t`Your backup is ready to download`, backupReadyToDownload: () => t`Your backup is ready to download`,
unlockVault: () => t`Unlock vault`, unlockVault: () => t`Unlock vault`,
unlockVaultDesc: () => t`Please enter your vault password to continue`, unlockVaultDesc: () => t`Please enter your vault password to continue`,
imagePreviewFailed: () => t`This image cannot be previewed` imagePreviewFailed: () => t`This image cannot be previewed`,
failedToCopyNote: () => t`Failed to copy note`
}; };