From 3dd9aed4ad06bd8ea583cf357304f085a60eff96 Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:15:37 +0000 Subject: [PATCH 01/11] introduce i18n lib --- package.json | 2 ++ yarn.lock | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/package.json b/package.json index b8848943..b7117a17 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "dom-to-image": "^2.6.0", "electron-window-state": "^5.0.3", "font-gis": "^1.0.6", + "i18next": "^24.2.3", "leaflet": "^1.9.4", "leaflet.nauticscale": "^1.1.0", "leaflet.polylinemeasure": "^3.0.0", @@ -49,6 +50,7 @@ "react": "^19.0.0", "react-dom": "^19.0.0", "react-error-boundary": "^5.0.0", + "react-i18next": "^15.4.1", "react-leaflet": "^5.0.0", "react-leaflet-custom-control": "^1.4.0", "react-leaflet-geoman-v2": "^1.0.1", diff --git a/yarn.lock b/yarn.lock index d71824e5..77f46e70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -960,6 +960,13 @@ dependencies: regenerator-runtime "^0.14.0" +"@babel/runtime@^7.25.0", "@babel/runtime@^7.26.10": + version "7.27.0" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.27.0.tgz#fbee7cf97c709518ecc1f590984481d5460d4762" + integrity sha512-VtPOkrdPHZsKc/clNqyi9WUA8TINkZ4cGk63UUE3u4pmB2k+ZMQRDuIOagv8UVd6j7k0T3+RRIb7beKTebNbcw== + dependencies: + regenerator-runtime "^0.14.0" + "@babel/template@^7.25.9", "@babel/template@^7.3.3": version "7.25.9" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.25.9.tgz#ecb62d81a8a6f5dc5fe8abfc3901fc52ddf15016" @@ -7346,6 +7353,13 @@ html-escaper@^2.0.0: resolved "https://registry.yarnpkg.com/html-escaper/-/html-escaper-2.0.2.tgz#dfd60027da36a36dfcbe236262c00a5822681453" integrity sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg== +html-parse-stringify@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz#dfc1017347ce9f77c8141a507f233040c59c55d2" + integrity sha512-KknJ50kTInJ7qIScF3jeaFRpMpE8/lfiTdzf/twXyPBLAGrLRTmkz3AdTnKeh40X8k9L2fdYwEp/42WGXIRGcg== + dependencies: + void-elements "3.1.0" + http-cache-semantics@^4.0.0, http-cache-semantics@^4.1.0: version "4.1.1" resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz#abe02fcb2985460bf0323be664436ec3476a6d5a" @@ -7409,6 +7423,13 @@ husky@^9.1.7: resolved "https://registry.yarnpkg.com/husky/-/husky-9.1.7.tgz#d46a38035d101b46a70456a850ff4201344c0b2d" integrity sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA== +i18next@^24.2.3: + version "24.2.3" + resolved "https://registry.yarnpkg.com/i18next/-/i18next-24.2.3.tgz#3a05f72615cbd7c00d7e348667e2aabef1df753b" + integrity sha512-lfbf80OzkocvX7nmZtu7nSTNbrTYR52sLWxPtlXX1zAhVw8WEnFk4puUkCR4B1dNQwbSpEHHHemcZu//7EcB7A== + dependencies: + "@babel/runtime" "^7.26.10" + iconv-lite@0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" @@ -10054,6 +10075,14 @@ react-fast-compare@^3.2.0: resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49" integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ== +react-i18next@^15.4.1: + version "15.4.1" + resolved "https://registry.yarnpkg.com/react-i18next/-/react-i18next-15.4.1.tgz#33f3e89c2f6c68e2bfcbf9aa59986ad42fe78758" + integrity sha512-ahGab+IaSgZmNPYXdV1n+OYky95TGpFwnKRflX/16dY04DsYYKHtVLjeny7sBSCREEcoMbAgSkFiGLF5g5Oofw== + dependencies: + "@babel/runtime" "^7.25.0" + html-parse-stringify "^3.0.1" + react-icons@^4.2.0: version "4.12.0" resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-4.12.0.tgz#54806159a966961bfd5cdb26e492f4dafd6a8d78" @@ -11946,6 +11975,11 @@ vite@^5.4.10: optionalDependencies: fsevents "~2.3.3" +void-elements@3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/void-elements/-/void-elements-3.1.0.tgz#614f7fbf8d801f0bb5f0661f5b2f5785750e4f09" + integrity sha512-Dhxzh5HZuiHQhbvTW9AMetFfBHDMYpo23Uo9btPXgdYP+3T5S+p+jgNy7spra+veYhBP2dCSgxR/i2Y02h5/6w== + walker@^1.0.8: version "1.0.8" resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.8.tgz#bd498db477afe573dc04185f011d3ab8a8d7653f" From 2019abc65cda63164fab59450a94f7e6ae95f6c2 Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:15:51 +0000 Subject: [PATCH 02/11] early steps --- src/components/WelcomePage/index.tsx | 15 +++++++++++++++ src/i18n.ts | 26 ++++++++++++++++++++++++++ src/locales/en.json | 0 src/locales/it.json | 0 4 files changed, 41 insertions(+) create mode 100644 src/i18n.ts create mode 100644 src/locales/en.json create mode 100644 src/locales/it.json diff --git a/src/components/WelcomePage/index.tsx b/src/components/WelcomePage/index.tsx index 87e4f0a9..e89351ad 100644 --- a/src/components/WelcomePage/index.tsx +++ b/src/components/WelcomePage/index.tsx @@ -1,5 +1,6 @@ import { Button, Col, Image, Row, Typography } from 'antd' import './styles.css' +import { useTranslation } from 'react-i18next'; interface WelcomePageProps { onDragOver: (event: React.DragEvent) => void @@ -9,6 +10,17 @@ interface WelcomePageProps { openExistingDocument: () => void } +const LanguageSelector = () => { + const { i18n } = useTranslation(); + + return ( + + ); +} + const WelcomePage: React.FC = ({ onDragOver, onDragLeave, @@ -51,6 +63,9 @@ const WelcomePage: React.FC = ({ +
+ +
{/* Debug info box */}
diff --git a/src/i18n.ts b/src/i18n.ts new file mode 100644 index 00000000..1d3f97e7 --- /dev/null +++ b/src/i18n.ts @@ -0,0 +1,26 @@ +import i18n from 'i18next'; +import { initReactI18next } from 'react-i18next'; + +i18n + .use(initReactI18next) + .init({ + resources: { + en: { + translation: { + // English translations + } + }, + it: { + translation: { + // Italian translations + } + } + }, + lng: "en", // default language + fallbackLng: "en", + interpolation: { + escapeValue: false + } + }); + +export default i18n; \ No newline at end of file diff --git a/src/locales/en.json b/src/locales/en.json new file mode 100644 index 00000000..e69de29b diff --git a/src/locales/it.json b/src/locales/it.json new file mode 100644 index 00000000..e69de29b From ebf8d3664e6c10abaffbb168259d9c9d99591c5e Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:18:41 +0000 Subject: [PATCH 03/11] reafactor component --- src/components/WelcomePage/LanguageSelector.tsx | 16 ++++++++++++++++ src/components/WelcomePage/index.tsx | 13 ++----------- 2 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 src/components/WelcomePage/LanguageSelector.tsx diff --git a/src/components/WelcomePage/LanguageSelector.tsx b/src/components/WelcomePage/LanguageSelector.tsx new file mode 100644 index 00000000..af4d38b7 --- /dev/null +++ b/src/components/WelcomePage/LanguageSelector.tsx @@ -0,0 +1,16 @@ +// src/components/WelcomePage/LanguageSelector.tsx +import React from 'react'; +import { useTranslation } from 'react-i18next'; + +const LanguageSelector: React.FC = () => { + const { i18n } = useTranslation(); + + return ( + + ); +} + +export default LanguageSelector; \ No newline at end of file diff --git a/src/components/WelcomePage/index.tsx b/src/components/WelcomePage/index.tsx index e89351ad..ebf2e5c2 100644 --- a/src/components/WelcomePage/index.tsx +++ b/src/components/WelcomePage/index.tsx @@ -1,6 +1,8 @@ +// src/components/WelcomePage/index.tsx import { Button, Col, Image, Row, Typography } from 'antd' import './styles.css' import { useTranslation } from 'react-i18next'; +import LanguageSelector from './LanguageSelector'; interface WelcomePageProps { onDragOver: (event: React.DragEvent) => void @@ -10,17 +12,6 @@ interface WelcomePageProps { openExistingDocument: () => void } -const LanguageSelector = () => { - const { i18n } = useTranslation(); - - return ( - - ); -} - const WelcomePage: React.FC = ({ onDragOver, onDragLeave, From ba1b353625600cf76bf51582879e552234a6b36d Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:21:07 +0000 Subject: [PATCH 04/11] first translation --- src/components/WelcomePage/index.tsx | 23 +++++++++++------------ src/i18n.ts | 16 +++++----------- src/locales/en.json | 11 +++++++++++ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/components/WelcomePage/index.tsx b/src/components/WelcomePage/index.tsx index ebf2e5c2..f19618ba 100644 --- a/src/components/WelcomePage/index.tsx +++ b/src/components/WelcomePage/index.tsx @@ -19,38 +19,38 @@ const WelcomePage: React.FC = ({ handleNew, openExistingDocument }) => { - // Get debug information from environment variables - const gitBranch = import.meta.env.VITE_GIT_BRANCH || 'unknown' + const { t } = useTranslation(); + const gitBranch = import.meta.env.VITE_GIT_BRANCH || t('unknown'); const buildDate = import.meta.env.VITE_BUILD_DATE ? new Date(import.meta.env.VITE_BUILD_DATE).toLocaleString() - : 'unknown' + : t('unknown'); return (
- Welcome to Albatross + {t('welcomeToAlbatross')}   - Application logo - albatross flying + {t('applicationLogoAlt')}   - Open an existing document or create a new one + {t('openOrCreateDocument')} - - + + - + @@ -58,12 +58,11 @@ const WelcomePage: React.FC = ({
- {/* Debug info box */}
- Branch: {gitBranch} | Build: {buildDate} + {t('branch')}: {gitBranch} | {t('build')}: {buildDate}
) } -export default WelcomePage +export default WelcomePage \ No newline at end of file diff --git a/src/i18n.ts b/src/i18n.ts index 1d3f97e7..0439c159 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -1,22 +1,16 @@ import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; +import enTranslations from './locales/en.json'; +import itTranslations from './locales/it.json'; i18n .use(initReactI18next) .init({ resources: { - en: { - translation: { - // English translations - } - }, - it: { - translation: { - // Italian translations - } - } + en: { translation: enTranslations }, + it: { translation: itTranslations }, }, - lng: "en", // default language + lng: "en", fallbackLng: "en", interpolation: { escapeValue: false diff --git a/src/locales/en.json b/src/locales/en.json index e69de29b..50ad4721 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -0,0 +1,11 @@ +{ + "welcomeToAlbatross": "Welcome to Albatross", + "applicationLogoAlt": "Application logo - albatross flying", + "openOrCreateDocument": "Open an existing document or create a new one", + "new": "New", + "samplePlot": "Sample plot", + "open": "Open", + "branch": "Branch", + "build": "Build", + "unknown": "unknown" +} \ No newline at end of file From 6b7ce4149584747fb4b4a7288b624090b11ec550 Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:21:55 +0000 Subject: [PATCH 05/11] italian translation --- src/locales/it.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/locales/it.json b/src/locales/it.json index e69de29b..4b7ad0f9 100644 --- a/src/locales/it.json +++ b/src/locales/it.json @@ -0,0 +1,11 @@ +{ + "welcomeToAlbatross": "Benvenuto in Albatross", + "applicationLogoAlt": "Logo dell'applicazione - albatross in volo", + "openOrCreateDocument": "Apri un documento esistente o creane uno nuovo", + "new": "Nuovo", + "samplePlot": "Grafico di esempio", + "open": "Apri", + "branch": "Ramo", + "build": "Compilazione", + "unknown": "sconosciuto" +} \ No newline at end of file From 047c0f5bfb27d0c83d0d8a2b9aa8b6872d398537 Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:24:02 +0000 Subject: [PATCH 06/11] add nl translations --- src/i18n.ts | 2 ++ src/locales/nl.json | 11 +++++++++++ 2 files changed, 13 insertions(+) create mode 100644 src/locales/nl.json diff --git a/src/i18n.ts b/src/i18n.ts index 0439c159..7f675862 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -2,6 +2,7 @@ import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; import enTranslations from './locales/en.json'; import itTranslations from './locales/it.json'; +import nlTranslations from './locales/nl.json'; i18n .use(initReactI18next) @@ -9,6 +10,7 @@ i18n resources: { en: { translation: enTranslations }, it: { translation: itTranslations }, + nl: { translation: nlTranslations } }, lng: "en", fallbackLng: "en", diff --git a/src/locales/nl.json b/src/locales/nl.json new file mode 100644 index 00000000..614848f9 --- /dev/null +++ b/src/locales/nl.json @@ -0,0 +1,11 @@ +{ + "welcomeToAlbatross": "Welkom bij Albatross", + "applicationLogoAlt": "Applicatielogo - vliegende albatros", + "openOrCreateDocument": "Open een bestaand document of maak een nieuw document", + "new": "Nieuw", + "samplePlot": "Voorbeeldgrafiek", + "open": "Openen", + "branch": "Tak", + "build": "Build", + "unknown": "onbekend" +} \ No newline at end of file From b331972e8ad73a4edb3ad6f3932a54997bff87a0 Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:29:52 +0000 Subject: [PATCH 07/11] fixes --- .../WelcomePage/LanguageSelector.tsx | 10 +++++----- src/components/WelcomePage/index.tsx | 10 +++++----- src/i18n.ts | 18 +++++++++--------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/components/WelcomePage/LanguageSelector.tsx b/src/components/WelcomePage/LanguageSelector.tsx index af4d38b7..c0806579 100644 --- a/src/components/WelcomePage/LanguageSelector.tsx +++ b/src/components/WelcomePage/LanguageSelector.tsx @@ -1,16 +1,16 @@ // src/components/WelcomePage/LanguageSelector.tsx -import React from 'react'; -import { useTranslation } from 'react-i18next'; +import React from 'react' +import { useTranslation } from 'react-i18next' const LanguageSelector: React.FC = () => { - const { i18n } = useTranslation(); + const { i18n } = useTranslation() return ( - ); + ) } -export default LanguageSelector; \ No newline at end of file +export default LanguageSelector \ No newline at end of file diff --git a/src/components/WelcomePage/index.tsx b/src/components/WelcomePage/index.tsx index f19618ba..cd26e184 100644 --- a/src/components/WelcomePage/index.tsx +++ b/src/components/WelcomePage/index.tsx @@ -1,8 +1,8 @@ // src/components/WelcomePage/index.tsx import { Button, Col, Image, Row, Typography } from 'antd' import './styles.css' -import { useTranslation } from 'react-i18next'; -import LanguageSelector from './LanguageSelector'; +import { useTranslation } from 'react-i18next' +import LanguageSelector from './LanguageSelector' interface WelcomePageProps { onDragOver: (event: React.DragEvent) => void @@ -19,11 +19,11 @@ const WelcomePage: React.FC = ({ handleNew, openExistingDocument }) => { - const { t } = useTranslation(); - const gitBranch = import.meta.env.VITE_GIT_BRANCH || t('unknown'); + const { t } = useTranslation() + const gitBranch = import.meta.env.VITE_GIT_BRANCH || t('unknown') const buildDate = import.meta.env.VITE_BUILD_DATE ? new Date(import.meta.env.VITE_BUILD_DATE).toLocaleString() - : t('unknown'); + : t('unknown') return (
diff --git a/src/i18n.ts b/src/i18n.ts index 7f675862..bb08e4d5 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -1,8 +1,8 @@ -import i18n from 'i18next'; -import { initReactI18next } from 'react-i18next'; -import enTranslations from './locales/en.json'; -import itTranslations from './locales/it.json'; -import nlTranslations from './locales/nl.json'; +import i18n from 'i18next' +import { initReactI18next } from 'react-i18next' +import enTranslations from './locales/en.json' +import itTranslations from './locales/it.json' +import nlTranslations from './locales/nl.json' i18n .use(initReactI18next) @@ -12,11 +12,11 @@ i18n it: { translation: itTranslations }, nl: { translation: nlTranslations } }, - lng: "en", - fallbackLng: "en", + lng: 'en', + fallbackLng: 'en', interpolation: { escapeValue: false } - }); + }) -export default i18n; \ No newline at end of file +export default i18n \ No newline at end of file From 70021e3af0ae8961f56021154ec0dd306808388e Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:34:49 +0000 Subject: [PATCH 08/11] introduce dutch --- src/components/WelcomePage/LanguageSelector.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/WelcomePage/LanguageSelector.tsx b/src/components/WelcomePage/LanguageSelector.tsx index c0806579..b66e47aa 100644 --- a/src/components/WelcomePage/LanguageSelector.tsx +++ b/src/components/WelcomePage/LanguageSelector.tsx @@ -9,6 +9,7 @@ const LanguageSelector: React.FC = () => { ) } From f922f158cb9f2c3734d24f47bff64fcd5064e5bc Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 17:37:21 +0000 Subject: [PATCH 09/11] fixes --- src/components/WelcomePage/LanguageSelector.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/WelcomePage/LanguageSelector.tsx b/src/components/WelcomePage/LanguageSelector.tsx index b66e47aa..bb33bb1f 100644 --- a/src/components/WelcomePage/LanguageSelector.tsx +++ b/src/components/WelcomePage/LanguageSelector.tsx @@ -5,11 +5,19 @@ import { useTranslation } from 'react-i18next' const LanguageSelector: React.FC = () => { const { i18n } = useTranslation() + const changeLanguage = (event: React.ChangeEvent) => { + const newLang = event.target.value + i18n.changeLanguage(newLang).then(() => { + // Force a re-render of the entire app + window.location.reload() + }) + } + return ( - - + ) } From e640ad7476d2b8c219d6d83e22ae5e30c0cfac9f Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 18:46:47 +0100 Subject: [PATCH 10/11] Update src/components/WelcomePage/index.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/components/WelcomePage/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/WelcomePage/index.tsx b/src/components/WelcomePage/index.tsx index cd26e184..2c904c1a 100644 --- a/src/components/WelcomePage/index.tsx +++ b/src/components/WelcomePage/index.tsx @@ -20,7 +20,7 @@ const WelcomePage: React.FC = ({ openExistingDocument }) => { const { t } = useTranslation() - const gitBranch = import.meta.env.VITE_GIT_BRANCH || t('unknown') + const gitBranch = import.meta.env.VITE_GIT_BRANCH || 'unknown' const buildDate = import.meta.env.VITE_BUILD_DATE ? new Date(import.meta.env.VITE_BUILD_DATE).toLocaleString() : t('unknown') From 909773044fd3622e172c65224d829f3e1725a9ad Mon Sep 17 00:00:00 2001 From: Ian Mayo Date: Fri, 4 Apr 2025 18:47:01 +0100 Subject: [PATCH 11/11] Update src/components/WelcomePage/index.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/components/WelcomePage/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/WelcomePage/index.tsx b/src/components/WelcomePage/index.tsx index 2c904c1a..65d92794 100644 --- a/src/components/WelcomePage/index.tsx +++ b/src/components/WelcomePage/index.tsx @@ -23,7 +23,7 @@ const WelcomePage: React.FC = ({ const gitBranch = import.meta.env.VITE_GIT_BRANCH || 'unknown' const buildDate = import.meta.env.VITE_BUILD_DATE ? new Date(import.meta.env.VITE_BUILD_DATE).toLocaleString() - : t('unknown') + : 'unknown' return (