i18n Utilities
The i18n utilities provide a complete internationalization system for the portfolio website, supporting Spanish (default) and English translations.Overview
Located insrc/i18n/utils.ts, this module exports translation utilities, language configuration, and type-safe translation functions.
Language Configuration
Supported Languages
Defines all supported languages with their display names
es: Spanish (Español)en: English
The default language used when no language is detected in the URL
Translation Structure
All translations are stored in a strongly-typed object with keys organized by section:Translation Categories
Navigation (nav.*)
Navigation (nav.*)
Hero Section (hero.*)
Hero Section (hero.*)
hero.greeting: Greeting texthero.name: Full namehero.role: Professional rolehero.bio: Biography descriptionhero.cta: Call-to-action button texthero.contact: Contact button text
About Section (about.*)
About Section (about.*)
about.title: Section titleabout.description: Description textabout.education: Education subsection titleabout.experience: Experience subsection titleabout.certifications: Certifications subsection title
Education Entries (edu.*)
Education Entries (edu.*)
Education-related translations for UADE and IFTS programs
Experience Entries (exp.*)
Experience Entries (exp.*)
Work experience translations for cloud engineering roles
Case Studies (case*.*, casestudies.*)
Case Studies (case*.*, casestudies.*)
Case study titles, challenges, solutions, and labels
Skills (skills.*, soft.*, lang.*)
Skills (skills.*, soft.*, lang.*)
Technical skills, soft skills, and language proficiency
Contact (contact.*)
Contact (contact.*)
Contact form and social media links
Footer (footer.*)
Footer (footer.*)
TypeScript Types
TranslationKey
Functions
getLangFromUrl
Extracts the language code from a URL pathname.The URL object to extract the language from
The detected language code, or
defaultLang if not found/ and checks if the second segment (index 1) matches a language in the translations object. If not found, returns defaultLang.
useTranslations
Creates a translation function for a specific language.The language code to create translations for
A translation function that accepts a
TranslationKey and returns the translated stringdefaultLang translation:
getLocalizedPath
Generates a localized URL path with optional hash.The language code for the path
Optional hash/anchor to append to the path
A formatted path string in the format
/{lang}/{hash}Usage in Astro Components
Typical usage pattern in an Astro component:Best Practices
Type Safety: Always use the
TranslationKey type to ensure translation keys are valid. The TypeScript compiler will catch typos and missing translations.Adding New Translations
- Add the key-value pair to both
esandenobjects in thetranslationsconstant - TypeScript will automatically update the
TranslationKeytype - Use the
t()function to access the new translation
Related Files
src/i18n/utils.ts: Source file (src/i18n/utils.ts:1)astro.config.mjs: i18n configuration (astro.config.mjs:6)- All
.astrocomponents insrc/components/: Consumers of these utilities