From dc0d66d28389fdfb2bcb0bf1cbd1a643870da694 Mon Sep 17 00:00:00 2001 From: Julio Ruiz Date: Sun, 15 Feb 2026 09:02:42 -0500 Subject: [PATCH] Added initial json files for translations - Adding example nav translations - Modified header to use translations. --- src/components/Header.astro | 23 +++++---- src/i18n/en.json | 8 +++ src/i18n/es.json | 8 +++ src/i18n/fr.json | 8 +++ src/i18n/he.json | 8 +++ src/i18n/index.ts | 39 ++++++++++++++ src/i18n/pt.json | 8 +++ src/i18n/uk.json | 8 +++ src/pages/[locale]/index.astro | 94 ++++++++++++++++++++++++++++++++++ 9 files changed, 194 insertions(+), 10 deletions(-) create mode 100644 src/i18n/en.json create mode 100644 src/i18n/es.json create mode 100644 src/i18n/fr.json create mode 100644 src/i18n/he.json create mode 100644 src/i18n/index.ts create mode 100644 src/i18n/pt.json create mode 100644 src/i18n/uk.json create mode 100644 src/pages/[locale]/index.astro diff --git a/src/components/Header.astro b/src/components/Header.astro index a0ba9e8..1508d67 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -1,22 +1,25 @@ --- import Button from "./ui/Button.astro"; import { Icon } from "astro-icon/components"; + +import { createTranslator } from "../i18n/index.ts"; +const tl = createTranslator(Astro.currentLocale); ---
diff --git a/src/i18n/en.json b/src/i18n/en.json new file mode 100644 index 0000000..de58331 --- /dev/null +++ b/src/i18n/en.json @@ -0,0 +1,8 @@ +{ + "nav.logo_line1": "Centro del Reino", + "nav.logo_line2": "de Paz y Justicia", + "nav.about": "About", + "nav.news": "News", + "nav.programs": "Programs", + "nav.contact": "Contact" +} \ No newline at end of file diff --git a/src/i18n/es.json b/src/i18n/es.json new file mode 100644 index 0000000..a1f1b0b --- /dev/null +++ b/src/i18n/es.json @@ -0,0 +1,8 @@ +{ + "nav.logo_line1": "Centro del Reino", + "nav.logo_line2": "de Paz y Justicia", + "nav.about": "Somos", + "nav.news": "Noticias", + "nav.programs": "Programas", + "nav.contact": "Contacto" +} \ No newline at end of file diff --git a/src/i18n/fr.json b/src/i18n/fr.json new file mode 100644 index 0000000..19a3197 --- /dev/null +++ b/src/i18n/fr.json @@ -0,0 +1,8 @@ +{ + "nav.logo_line1": "Centro del Reino", + "nav.logo_line2": "de Paz y Justicia", + "nav.about": "À propos", + "nav.news": "Nouvelles", + "nav.programs": "Programmes", + "nav.contact": "Contactez" +} \ No newline at end of file diff --git a/src/i18n/he.json b/src/i18n/he.json new file mode 100644 index 0000000..19a3197 --- /dev/null +++ b/src/i18n/he.json @@ -0,0 +1,8 @@ +{ + "nav.logo_line1": "Centro del Reino", + "nav.logo_line2": "de Paz y Justicia", + "nav.about": "À propos", + "nav.news": "Nouvelles", + "nav.programs": "Programmes", + "nav.contact": "Contactez" +} \ No newline at end of file diff --git a/src/i18n/index.ts b/src/i18n/index.ts new file mode 100644 index 0000000..56e375b --- /dev/null +++ b/src/i18n/index.ts @@ -0,0 +1,39 @@ +import es from "./es.json"; +import en from "./en.json"; +import fr from "./fr.json"; +import he from "./he.json"; +import uk from "./uk.json"; +import pt from "./pt.json"; + +const dictionaries = { es, en, fr, he, uk, pt } as const; +export type Locale = keyof typeof dictionaries; + +// Optional: type-safe keys from the default dictionary +export type I18nKey = keyof typeof es; + +export function t( + locale: string | undefined, + key: I18nKey, + vars?: Record +) { + const l = (locale in dictionaries ? locale : "es") as Locale; + + // fallback chain: requested locale -> default locale -> key itself + const template = + dictionaries[l][key] ?? + dictionaries.it[key] ?? + String(key); + + if (!vars) return template; + + // simple interpolation: "Hello {name}" + return template.replace(/\{(\w+)\}/g, (_, name) => + vars[name] === undefined ? `{${name}}` : String(vars[name]) + ); +} + +export function createTranslator(locale: string | undefined) { + return function tl(key: I18nKey, vars?: Record) { + return t(locale, key, vars); + }; +} \ No newline at end of file diff --git a/src/i18n/pt.json b/src/i18n/pt.json new file mode 100644 index 0000000..a1f1b0b --- /dev/null +++ b/src/i18n/pt.json @@ -0,0 +1,8 @@ +{ + "nav.logo_line1": "Centro del Reino", + "nav.logo_line2": "de Paz y Justicia", + "nav.about": "Somos", + "nav.news": "Noticias", + "nav.programs": "Programas", + "nav.contact": "Contacto" +} \ No newline at end of file diff --git a/src/i18n/uk.json b/src/i18n/uk.json new file mode 100644 index 0000000..a1f1b0b --- /dev/null +++ b/src/i18n/uk.json @@ -0,0 +1,8 @@ +{ + "nav.logo_line1": "Centro del Reino", + "nav.logo_line2": "de Paz y Justicia", + "nav.about": "Somos", + "nav.news": "Noticias", + "nav.programs": "Programas", + "nav.contact": "Contacto" +} \ No newline at end of file diff --git a/src/pages/[locale]/index.astro b/src/pages/[locale]/index.astro new file mode 100644 index 0000000..19d6059 --- /dev/null +++ b/src/pages/[locale]/index.astro @@ -0,0 +1,94 @@ +--- +import "../../styles/global.css"; + +import MainLayout from "../../layouts/MainLayout.astro"; +import HeroHome from "../../components/HeroHome.astro"; +import NewsSection from "../../components/section/NewsSection.astro"; +import ParticipateSection from "../../components/section/ParticipateSection.astro"; +import CarouselSection from "../../components/section/CarouselSection.astro"; +import InfoSection from "../../components/section/InfoSection.astro"; +import IdentitySection from "../../components/section/IdentitySection.astro"; +import AuthoritySection from "../../components/section/AuthoritySection.astro"; +import ProjectionSection from "../../components/section/ProjectionSection.astro"; + +import { infoboxes } from "../../data/content/infosection.js"; +import ColorSection from "../../components/section/ColorSection.astro"; +import TitleSection from "../../components/section/TitleSection.astro"; +import GridSection from "../../components/section/GridSection.astro"; +import ColumnsSection from "../../components/section/ColumnsSection.astro"; +import FormationSection from "../../components/section/FormationSection.astro"; +import FooterSection from "../../components/section/FooterSection.astro"; + +const { locale } = Astro.params; + +const carouselImages2 = [ + { + image: "https://ik.imagekit.io/crpy/tr:w-1920,h-1080,cm-extract,x-0,y-1730/lonely-african-american-male-praying-with-his-hands-bible-with-his-head-down.webp", + text: "Justicia", + }, + { + image: "https://ik.imagekit.io/crpy/amigos-bn.webp", + text: "Paz", + }, +]; + +const carouselImages3 = [ + { + image: "https://ik.imagekit.io/crpy/tr:w-1920,h-1080,cm-extract,x-0,y-1730/lonely-african-american-male-praying-with-his-hands-bible-with-his-head-down.webp", + text: "Justicia", + }, + { + image: "https://ik.imagekit.io/crpy/amigos-bn.webp", + text: "Paz", + }, +]; +--- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +