diff --git a/src/App.jsx b/src/App.jsx
index 0c07476..9e69b78 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -12,8 +12,8 @@ import PubNoteSafe from "./pages/pubNoteSafe";
import RenderMarkdown from "./components/markdown";
import socket from "./components/socket";
import Settings from "./pages/settings";
-import Locales from "./localisation/main";
import { useState } from "react";
+import { localesProcess } from "./components/utils";
function App() {
Storage.prototype.setObj = function (key, obj) {
@@ -26,11 +26,8 @@ function App() {
const [key, setKey] = useState(Math.random());
window.settings = localStorage.getObj("settings") || {};
- window.locals =
- Locales[window.settings.language] ||
- Locales[navigator.language] ||
- Locales[navigator.userLanguage] ||
- Locales.en;
+
+ localesProcess();
window.addEventListener("reRenderPage", () => {
setKey(Math.random());
diff --git a/src/components/note.jsx b/src/components/note.jsx
index 519b010..ba2a29d 100644
--- a/src/components/note.jsx
+++ b/src/components/note.jsx
@@ -10,7 +10,7 @@ function Note({ note }) {
{`${printDate(note.time)} ${
- note.pub ? "| Публичная" : "| Локальная"
+ note.pub ? `| ${locals.PublicNote}` : `| ${locals.LocalNote}`
}`}
diff --git a/src/components/utils.js b/src/components/utils.js
index 52f7a5a..0eeffaf 100644
--- a/src/components/utils.js
+++ b/src/components/utils.js
@@ -1,25 +1,30 @@
+import { Locales } from "../localisation/main";
+
function printDate(time) {
time = new Date(time);
- function padStr(i) {
- return i < 10 ? "0" + i : "" + i;
- }
-
- let dateStr =
- settings.language === "ru" || settings.language === "ru-RU"
- ? `${padStr(time.getHours())}:${padStr(time.getMinutes())}:${padStr(
- time.getSeconds()
- )} ${padStr(time.getDate())}.${padStr(1 + time.getMonth())}.${padStr(
- time.getFullYear()
- )}`
- : `${time.toLocaleTimeString("en-US")} ${padStr(
- 1 + time.getMonth()
- )}/${padStr(time.getDate())}/${padStr(time.getFullYear())}`;
-
- return dateStr;
+ return time.toLocaleString(settings.language);
}
function reRenderPage() {
window.dispatchEvent(new Event("reRenderPage"));
}
-export { printDate, reRenderPage };
+function localesProcess(reRender) {
+ let locale =
+ window.settings.language ||
+ navigator.language ||
+ navigator.userLanguage ||
+ "en-US";
+
+ let lang = locale.split("-")[0];
+
+ let localeObj = Object.assign({}, Locales.en);
+ Object.assign(localeObj, Locales[lang]);
+ Object.assign(localeObj, Locales[locale]);
+
+ window.locals = localeObj;
+
+ if (reRender) reRenderPage();
+}
+
+export { printDate, reRenderPage, localesProcess };
diff --git a/src/localisation/en.js b/src/localisation/en.js
index 3586e01..c4a89a0 100644
--- a/src/localisation/en.js
+++ b/src/localisation/en.js
@@ -52,6 +52,8 @@ let en = {
Sync: "Sync",
Search: "Search",
NoNotesFound: "No notes found",
+ LocalNote: "Local",
+ PublicNote: "Public",
};
export default en;
diff --git a/src/localisation/es.js b/src/localisation/es.js
new file mode 100644
index 0000000..c521eb2
--- /dev/null
+++ b/src/localisation/es.js
@@ -0,0 +1,62 @@
+//translated with Google Translate
+//if you want to help with translations, please contribute to this project
+
+let es = {
+ Notes: "Notas",
+ Write: "Escribir",
+ Chat: "Charlar",
+ Settings: "Ajustes",
+ About: "Acerca de",
+ Name: "Nombre",
+ UserName: "Nombre de usuario",
+ User: "Usuaria",
+ PhotoUrl: "URL fotográfica",
+ Url: "Url",
+ Status: "Estado",
+ UserStatus: "Estatus de usuario",
+ EditPreview: "Edición en vista previa",
+ EditPreviewWarn:
+ "Puede causar cambios de texto irreversibles, como etiquetas de código de ruptura",
+ PublicNote: "Nota pública",
+ PublicNoteTitle:
+ "Si está habilitado, Note será visible para todos los usuarios",
+ Interface: "Interfaz",
+ Language: "Idioma",
+ ThirdPartyApi: "API de terceros",
+ OpenAiKey: "Clave de API de OpenAI",
+ Key: "Llave",
+ Preview: "Avance",
+ NotePlaceholder: "Tu nota comienza aquí.Puede usar Markdown, MathJax y GFM.",
+ NoteName: "Nombre de nota",
+ Publish: "Publicar",
+ Save: "Ahorrar",
+ WriteNote: "Toma nota",
+ PubError: "Error en la nota de publicación",
+ PubErrorMsg: "La nota no se publicó debido a un error desconocido",
+ PubErrorMsgNoName: "No se publicó una nota, porque no tiene un nombre.",
+ PubErrorMsgNoText: "La nota no se publicó, porque no tiene un texto.",
+ Back: "Atrás",
+ PubNoteNotExist: "Esta nota no existe",
+ NoteNotExist: "Esta nota no existe",
+ Idontexists: "No existe",
+ PubUrlPlaceholder:
+ "El enlace para enviar una nota pública.Cuando haga clic en este enlace, la nota desaparecerá del servidor y se guardará localmente.",
+ Delete: "Borrar",
+ Open: "Abierto",
+ NoNotesYet: "No hay notas todavía",
+ AIComplete: "Continuar nota (ai)",
+ AdditionalFeatures: "Características adicionales",
+ CollabEdit: "Edición colaborativa",
+ Password: "Contraseña",
+ SyncPassword: "Sincronización de contraseña",
+ CollabEditPassword: "Contraseña para edición colaborativa",
+ BroadcastSync: "Obtener notas, configuraciones de otro dispositivo",
+ SyncAll: "Envío de datos",
+ Sync: "Sincronización",
+ Search: "Buscar",
+ NoNotesFound: "No se encontraron notas",
+ LocalNote: "Local",
+ PublicNote: "Pública",
+};
+
+export default es;
diff --git a/src/localisation/main.js b/src/localisation/main.js
index 206d363..2355452 100644
--- a/src/localisation/main.js
+++ b/src/localisation/main.js
@@ -1,22 +1,26 @@
import ru from "./ru";
import en from "./en";
+import es from "./es";
let Locales = {
ru,
en,
- "en-US": en,
- "en-AU": en,
- "en-BZ": en,
- "en-CA": en,
- "en-IE": en,
- "en-JM": en,
- "en-NZ": en,
- "en-ZA": en,
- "en-TT": en,
- "en-GB": en,
- "en-US": en,
-
- "ru-RU": ru,
+ es,
};
-export default Locales;
+let langChoices = [
+ {
+ value: "ru-RU",
+ label: "Русский",
+ },
+ {
+ value: "en-US",
+ label: "English (US)",
+ },
+ {
+ value: "es",
+ label: "Español",
+ },
+];
+
+export { Locales, langChoices };
diff --git a/src/localisation/ru.js b/src/localisation/ru.js
index f46d507..1f710bd 100644
--- a/src/localisation/ru.js
+++ b/src/localisation/ru.js
@@ -53,6 +53,8 @@ let ru = {
Sync: "Синхронизация",
Search: "Поиск",
NoNotesFound: "Заметок не найдено",
+ LocalNote: "Локальная",
+ PublishNote: "Публичная",
};
export default ru;
diff --git a/src/pages/settings.jsx b/src/pages/settings.jsx
index b364ec5..2b76019 100644
--- a/src/pages/settings.jsx
+++ b/src/pages/settings.jsx
@@ -5,10 +5,10 @@ import {
SettingsSection,
setSetting,
} from "../components/settingsInputs";
-import { reRenderPage } from "../components/utils";
-import Locales from "../localisation/main";
import { ButtonWithIcon } from "../components/button";
import { ChevronDoubleRightIcon } from "@heroicons/react/24/outline";
+import { localesProcess } from "../components/utils";
+import { langChoices } from "../localisation/main";
function Settings() {
return (
@@ -109,25 +109,10 @@ function Settings() {
{
- window.locals =
- Locales[window.settings.language] ||
- Locales[navigator.language] ||
- Locales[navigator.userLanguage] ||
- Locales.en;
-
+ options={langChoices}
+ onChange={() => {
+ localesProcess(true);
setSetting("newNotes", false);
- reRenderPage();
}}
/>