Translation System
Translations are managed in a centralized file atsrc/utils/i18n.ts. The system uses a simple key-value object structure for each language.
Translation Object Structure
Core i18n Functions
getLangFromUrl()
Extracts the language from the URL pathname.useTranslations()
Returns a translation function for the specified language with support for variable interpolation.getLocalizedPath()
Generates localized URL paths with language prefixes.Dynamic Routing
Pages use Astro’s[lang] dynamic parameter to generate static routes for each language.
Example from src/pages/[lang]/buscar.astro:
/es/buscar/(Spanish)/en/buscar/(English)
Translation Categories
Translations are organized by feature area:| Category | Keys | Purpose |
|---|---|---|
home.* | Title, description, search, about sections | Homepage content |
search.* | Search UI, results, categories | Search functionality |
word.* | Definition, examples, synonyms | Word detail pages |
nav.* | Navigation links | Site navigation |
schema.* | SEO metadata | Structured data |
Variable Interpolation
Translation keys support variable interpolation using{variableName} syntax.
Translation definition:
Adding New Languages
SEO Integration
Translations are used in meta tags and structured data:Client-Side Translations
For client-side JavaScript, translations are passed viadefine:vars:
Best Practices
Use consistent key naming
Use consistent key naming
Follow the pattern
section.subsection.key for organization:home.search.placeholdersearch.category.sustantivoword.definition
Keep default language as fallback
Keep default language as fallback
The system defaults to Spanish (
es) if an invalid language is detected, ensuring content is always displayed.Translate all UI strings
Translate all UI strings
Ensure every user-facing string has entries in both
es and en objects to prevent missing translations.Use variables for dynamic content
Use variables for dynamic content
For counts, names, or other dynamic values, use variable interpolation instead of string concatenation: