feat: locales processing and Spanish

This commit is contained in:
Artemy 2023-04-06 17:19:58 +03:00
parent a34ae82215
commit 2317dd6fdc
8 changed files with 115 additions and 58 deletions

View file

@ -12,8 +12,8 @@ import PubNoteSafe from "./pages/pubNoteSafe";
import RenderMarkdown from "./components/markdown"; import RenderMarkdown from "./components/markdown";
import socket from "./components/socket"; import socket from "./components/socket";
import Settings from "./pages/settings"; import Settings from "./pages/settings";
import Locales from "./localisation/main";
import { useState } from "react"; import { useState } from "react";
import { localesProcess } from "./components/utils";
function App() { function App() {
Storage.prototype.setObj = function (key, obj) { Storage.prototype.setObj = function (key, obj) {
@ -26,11 +26,8 @@ function App() {
const [key, setKey] = useState(Math.random()); const [key, setKey] = useState(Math.random());
window.settings = localStorage.getObj("settings") || {}; window.settings = localStorage.getObj("settings") || {};
window.locals =
Locales[window.settings.language] || localesProcess();
Locales[navigator.language] ||
Locales[navigator.userLanguage] ||
Locales.en;
window.addEventListener("reRenderPage", () => { window.addEventListener("reRenderPage", () => {
setKey(Math.random()); setKey(Math.random());

View file

@ -10,7 +10,7 @@ function Note({ note }) {
</h2> </h2>
<div className="justify-self-center lg:justify-self-end"> <div className="justify-self-center lg:justify-self-end">
{`${printDate(note.time)} ${ {`${printDate(note.time)} ${
note.pub ? "| Публичная" : "| Локальная" note.pub ? `| ${locals.PublicNote}` : `| ${locals.LocalNote}`
}`} }`}
</div> </div>
</div> </div>

View file

@ -1,25 +1,30 @@
import { Locales } from "../localisation/main";
function printDate(time) { function printDate(time) {
time = new Date(time); time = new Date(time);
function padStr(i) { return time.toLocaleString(settings.language);
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;
} }
function reRenderPage() { function reRenderPage() {
window.dispatchEvent(new Event("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 };

View file

@ -52,6 +52,8 @@ let en = {
Sync: "Sync", Sync: "Sync",
Search: "Search", Search: "Search",
NoNotesFound: "No notes found", NoNotesFound: "No notes found",
LocalNote: "Local",
PublicNote: "Public",
}; };
export default en; export default en;

62
src/localisation/es.js Normal file
View file

@ -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;

View file

@ -1,22 +1,26 @@
import ru from "./ru"; import ru from "./ru";
import en from "./en"; import en from "./en";
import es from "./es";
let Locales = { let Locales = {
ru, ru,
en, en,
"en-US": en, es,
"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,
}; };
export default Locales; let langChoices = [
{
value: "ru-RU",
label: "Русский",
},
{
value: "en-US",
label: "English (US)",
},
{
value: "es",
label: "Español",
},
];
export { Locales, langChoices };

View file

@ -53,6 +53,8 @@ let ru = {
Sync: "Синхронизация", Sync: "Синхронизация",
Search: "Поиск", Search: "Поиск",
NoNotesFound: "Заметок не найдено", NoNotesFound: "Заметок не найдено",
LocalNote: "Локальная",
PublishNote: "Публичная",
}; };
export default ru; export default ru;

View file

@ -5,10 +5,10 @@ import {
SettingsSection, SettingsSection,
setSetting, setSetting,
} from "../components/settingsInputs"; } from "../components/settingsInputs";
import { reRenderPage } from "../components/utils";
import Locales from "../localisation/main";
import { ButtonWithIcon } from "../components/button"; import { ButtonWithIcon } from "../components/button";
import { ChevronDoubleRightIcon } from "@heroicons/react/24/outline"; import { ChevronDoubleRightIcon } from "@heroicons/react/24/outline";
import { localesProcess } from "../components/utils";
import { langChoices } from "../localisation/main";
function Settings() { function Settings() {
return ( return (
@ -109,25 +109,10 @@ function Settings() {
<SettingsSelectInput <SettingsSelectInput
label={locals.Language} label={locals.Language}
settingName="language" settingName="language"
options={[ options={langChoices}
{ onChange={() => {
value: "ru", localesProcess(true);
label: "Русский",
},
{
value: "en",
label: "English (US)",
},
]}
onChange={(e) => {
window.locals =
Locales[window.settings.language] ||
Locales[navigator.language] ||
Locales[navigator.userLanguage] ||
Locales.en;
setSetting("newNotes", false); setSetting("newNotes", false);
reRenderPage();
}} }}
/> />
</SettingsSection> </SettingsSection>