mirror of
https://github.com/artegoser/AnoPaper.git
synced 2024-11-22 03:46:22 +03:00
feat: locales processing and Spanish
This commit is contained in:
parent
a34ae82215
commit
2317dd6fdc
8 changed files with 115 additions and 58 deletions
|
@ -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());
|
||||
|
|
|
@ -10,7 +10,7 @@ function Note({ note }) {
|
|||
</h2>
|
||||
<div className="justify-self-center lg:justify-self-end">
|
||||
{`${printDate(note.time)} ${
|
||||
note.pub ? "| Публичная" : "| Локальная"
|
||||
note.pub ? `| ${locals.PublicNote}` : `| ${locals.LocalNote}`
|
||||
}`}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -52,6 +52,8 @@ let en = {
|
|||
Sync: "Sync",
|
||||
Search: "Search",
|
||||
NoNotesFound: "No notes found",
|
||||
LocalNote: "Local",
|
||||
PublicNote: "Public",
|
||||
};
|
||||
|
||||
export default en;
|
||||
|
|
62
src/localisation/es.js
Normal file
62
src/localisation/es.js
Normal 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;
|
|
@ -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 };
|
||||
|
|
|
@ -53,6 +53,8 @@ let ru = {
|
|||
Sync: "Синхронизация",
|
||||
Search: "Поиск",
|
||||
NoNotesFound: "Заметок не найдено",
|
||||
LocalNote: "Локальная",
|
||||
PublishNote: "Публичная",
|
||||
};
|
||||
|
||||
export default ru;
|
||||
|
|
|
@ -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() {
|
|||
<SettingsSelectInput
|
||||
label={locals.Language}
|
||||
settingName="language"
|
||||
options={[
|
||||
{
|
||||
value: "ru",
|
||||
label: "Русский",
|
||||
},
|
||||
{
|
||||
value: "en",
|
||||
label: "English (US)",
|
||||
},
|
||||
]}
|
||||
onChange={(e) => {
|
||||
window.locals =
|
||||
Locales[window.settings.language] ||
|
||||
Locales[navigator.language] ||
|
||||
Locales[navigator.userLanguage] ||
|
||||
Locales.en;
|
||||
|
||||
options={langChoices}
|
||||
onChange={() => {
|
||||
localesProcess(true);
|
||||
setSetting("newNotes", false);
|
||||
reRenderPage();
|
||||
}}
|
||||
/>
|
||||
</SettingsSection>
|
||||
|
|
Loading…
Add table
Reference in a new issue