From 23fa4423198936322989f27566b087b84abdc594 Mon Sep 17 00:00:00 2001 From: SrIzan10 <66965250+SrIzan10@users.noreply.github.com> Date: Wed, 16 Aug 2023 16:16:19 +0200 Subject: [PATCH] feat: localization support and spanish translation --- .eslintrc.cjs | 5 ++-- electron/index.ts | 14 +++++++--- locales/en.json | 40 ++++++++++++++++++++++++++++ locales/es.json | 40 ++++++++++++++++++++++++++++ package.json | 4 ++- src/App.tsx | 4 +-- src/Footer.tsx | 40 +++++++++++++++------------- src/FunctionalityCard.tsx | 30 ++++++++++++++------- src/InitModal.tsx | 56 ++++++++++++++++++--------------------- src/LanguageSelector.css | 14 ++++++++++ src/LanguageSelector.tsx | 38 ++++++++++++++++++++++++++ src/main.tsx | 21 ++++++++++++++- tsconfig.json | 3 ++- yarn.lock | 27 +++++++++++++++++++ 14 files changed, 268 insertions(+), 68 deletions(-) create mode 100644 locales/en.json create mode 100644 locales/es.json create mode 100644 src/LanguageSelector.css create mode 100644 src/LanguageSelector.tsx diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 6ee98ca..a4fbc8c 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -14,6 +14,7 @@ module.exports = { ecmaVersion: 'latest', sourceType: 'module', tsconfigRootDir: __dirname, + project: '.swcrc' }, plugins: ['react-refresh'], rules: { @@ -21,6 +22,6 @@ module.exports = { 'warn', { allowConstantExport: true }, ], - '@typescript-eslint/no-non-null-assertion': 'off', - }, + '@typescript-eslint/no-non-null-assertion': 'off' + } } diff --git a/electron/index.ts b/electron/index.ts index 9ff6477..c6d4ba0 100644 --- a/electron/index.ts +++ b/electron/index.ts @@ -1,6 +1,6 @@ -import path from 'node:path' +import * as path from 'node:path' import { app, BrowserWindow, dialog, ipcMain } from 'electron'; -import isDev from 'electron-is-dev'; +import * as isDev from 'electron-is-dev'; import * as colorette from 'colorette'; import * as fs from 'node:fs' import * as os from 'node:os' @@ -47,7 +47,7 @@ function createWindow() { }); }); - ipcMain.on('submitForm', async (event, data) => { + ipcMain.on('submitForm', async (event, data: InitModalData) => { const fileName = createRandomFileName('txt') // Process the submitted data here writeLineToLogAndConsole(`${colorette.green('✓')} Received sern init submit form data:`, fileName); @@ -192,4 +192,12 @@ function randomstring(length: number) { counter += 1; } return result; +} + +interface InitModalData { + projectName: string, + chosenTemplate: string, + installPackages: boolean, + chosenPackageManager: string, + selectedPath: string } \ No newline at end of file diff --git a/locales/en.json b/locales/en.json new file mode 100644 index 0000000..53524fe --- /dev/null +++ b/locales/en.json @@ -0,0 +1,40 @@ +{ + "credits": { + "propsTo": "@SrIzan10 (original language for this project)", + "btw": "All COMMENT_FOR_TRANSLATOR keys are comments that help you how to write translations. Follow these so you get approved faster." + }, + "translation": { + "functionalityCard": { + "init": { + "description": "Scaffold a new project" + }, + "plugins": { + "description": "Manage the plugins of an existing project" + } + }, + "initModal": { + "openModalButton": "Get started", + "projectName": "Project name", + "selectTemplate": "Select a template", + "couldntFetchTemplates": "Couldn't fetch templates! Please do CTRL+R (u online?)", + "installPackagesCheckbox": "Install packages while you're at it", + "selectPackageManager": "Select a package manager", + "chooseDirectoryButton": "Select directory", + "selectedDirectory": "Selected directory:", + "goButton": "Go!", + "commandSuccessful": "The command was successful!", + "commandFailed": "The command failed!", + "COMMENT_FOR_TRANSLATOR": "keep this uppercase", + "openLogFile": "OPEN LOG FILE", + "COMMENT_FOR_TRANSLATOR_2": "the next string is used to change the text 'with' in the sentence 'with '", + "with": "with" + }, + "footer": { + "COMMENT_FOR_TRANSLATOR": "Keep all the strings here as lowercase. It kinda gives a good vibe to the text :D", + "web": "front page", + "COMMENT_FOR_TRANSLATOR_2": "Keep these at their current state. They are brands after all, so you shouldn't change these unless they are called differently in other languages", + "github": "github", + "discord": "discord" + } + } +} \ No newline at end of file diff --git a/locales/es.json b/locales/es.json new file mode 100644 index 0000000..49d7453 --- /dev/null +++ b/locales/es.json @@ -0,0 +1,40 @@ +{ + "credits": { + "propsTo": "@SrIzan10 (spanish me)", + "btw": "Todos los COMMENT_FOR_TRANSLATOR son entradas que te ayudan a traducir los textos siguiendo unas reglas. Sigue estas para ser aprobado más fácilmente." + }, + "translation": { + "functionalityCard": { + "init": { + "description": "Inicia un nuevo proyecto" + }, + "plugins": { + "description": "Administra los plugins de un proyecto existente" + } + }, + "initModal": { + "openModalButton": "Empezar", + "projectName": "Nombre del proyecto", + "selectTemplate": "Selecciona una plantilla", + "couldntFetchTemplatesError": "No se pudieron obtener las plantillas. Haz CTRL+R. (¿Estás conectado a internet?)", + "installPackagesCheckbox": "De paso instala las depencencias", + "selectPackageManager": "Selecciona un gestor de paquetes", + "chooseDirectoryButton": "Selecciona un directorio", + "selectedDirectory": "Directorio seleccionado:", + "goButton": "¡Vamos!", + "commandSuccessful": "El comando se ejecutó con éxito!", + "commandFailed": "El comando falló.", + "COMMENT_FOR_TRANSLATOR": "Mantén esto en mayúsculas", + "openLogFile": "Abrir archivo de registro", + "COMMENT_FOR_TRANSLATOR_2": "El texto de abajo sirve para reemplazar 'with' en las opciones de plantilla con lo de abajo. No cambiar.", + "with": "con" + }, + "footer": { + "COMMENT_FOR_TRANSLATOR": "Mantén todos los textos aquí en minúsculas. Le dan un buen vibe al texto :D", + "web": "web", + "COMMENT_FOR_TRANSLATOR_2": "Mantén estos textos así. Al fin y al cabo son marcas, así que no deberías cambiarlas excepto si se llaman de otra forma en el idioma.", + "github": "github", + "discord": "discord" + } + } +} \ No newline at end of file diff --git a/package.json b/package.json index 0186ba0..42fe9c3 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,10 @@ "@mui/material": "^5.13.4", "colorette": "^2.0.20", "electron-is-dev": "^2.0.0", + "i18next": "^23.4.4", "react": "^18.2.0", - "react-dom": "^18.2.0" + "react-dom": "^18.2.0", + "react-i18next": "^13.1.2" }, "devDependencies": { "@swc/cli": "^0.1.62", diff --git a/src/App.tsx b/src/App.tsx index 9352a90..c222ee6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,6 +3,7 @@ import Footer from './Footer.js'; import './FunctionalityCard.js'; import FunctionalityCard from './FunctionalityCard.js'; import { ThemeProvider, createTheme } from '@mui/material/styles'; +import LanguageSelector from './LanguageSelector'; const darkTheme = createTheme({ palette: { @@ -17,15 +18,14 @@ function App() { return (
+

~$ sern