Skip to main content
The i18n system provides bilingual support (Spanish and English) for the Adosa Real Estate platform.

Configuration

Supported Languages

export const languages = {
  es: 'Español',
  en: 'English',
};

export const defaultLang = 'es';
The platform supports Spanish (es) as the default language and English (en) as an alternative.

Translation Object

The ui object contains all translation keys for both languages:
export const ui = {
  es: { /* Spanish translations */ },
  en: { /* English translations */ }
} as const;

Available Translation Keys

nav.home
string
ES: “Sobre Adosa” | EN: “About Adosa”
nav.properties
string
ES: “Propiedades” | EN: “Properties”
nav.mission
string
ES: “Misión” | EN: “Mission”
nav.contact
string
ES: “Contacto” | EN: “Contact”
ES: “Todos los derechos reservados” | EN: “All rights reserved”
ES: “Política de privacidad” | EN: “Privacy Policy”
ES: “Política de Cookies” | EN: “Cookies Policy”

Property Details

property.bedrooms
string
ES: “Dorm.” | EN: “Beds”
property.bathrooms
string
ES: “Baños” | EN: “Baths”
property.built
string
ES: “m² Construido” | EN: “m² Built”
property.plot
string
ES: “m² Parcela” | EN: “m² Plot”
property.price
string
ES: “Precio” | EN: “Price”
property.details
string
ES: “Detalles” | EN: “Details”
property.description
string
ES: “Descripción” | EN: “Description”
property.location
string
ES: “Ubicación” | EN: “Location”
property.type
string
ES: “Tipo” | EN: “Type”
property.reference
string
ES: “Referencia” | EN: “Reference”
property.energy
string
ES: “Cert. Energético” | EN: “Energy Cert.”
property.community
string
ES: “Comunidad” | EN: “Community”
property.ibi
string
ES: “IBI” | EN: “IBI”

Property Grid Filters

grid.location
string
ES: “Ubicación” | EN: “Location”
grid.typology
string
ES: “Tipología” | EN: “Typology”
grid.beds
string
ES: “Habitaciones” | EN: “Bedrooms”
grid.baths
string
ES: “Baños” | EN: “Bathrooms”
grid.all
string
ES: “Todos” | EN: “All” (masculine)
grid.all_f
string
ES: “Todas” | EN: “All” (feminine)
grid.any
string
ES: “Cualquiera” | EN: “Any”

Property Types

grid.apartment
string
ES: “Apartamento” | EN: “Apartment”
grid.house
string
ES: “Casa” | EN: “House”
grid.land
string
ES: “Terreno” | EN: “Land”
grid.project
string
ES: “Parcela” | EN: “Plots”
grid.attic
string
ES: “Ático” | EN: “Penthouse”
grid.apartments
string
ES: “Apartamentos” | EN: “Apartments” (plural)
grid.houses
string
ES: “Casas” | EN: “Houses” (plural)
grid.lands
string
ES: “Terrenos” | EN: “Lands” (plural)
grid.projects
string
ES: “Parcelas” | EN: “Plots” (plural)
grid.commercial
string
ES: “Local Comercial” | EN: “Commercial Property”
ES: “DESTACADO” | EN: “FEATURED”
grid.bed_unit
string
ES: “Dorm.” | EN: “Bed”
grid.bath_unit
string
ES: “Baño” | EN: “Bath”

Contact Form

contact.title
string
ES: “Hablemos” | EN: “Let’s Talk”
contact.name
string
ES: “Nombre” | EN: “Name”
contact.phone
string
ES: “Teléfono” | EN: “Phone”
contact.email
string
ES: “Email” | EN: “Email”
contact.message
string
ES: “Mensaje” | EN: “Message”
contact.send
string
ES: “ENVIAR” | EN: “SEND”

Utility Functions

getLangFromUrl()

Extracts the language code from a URL pathname.
function getLangFromUrl(url: URL): keyof typeof ui

Parameters

url
URL
required
URL object to extract language from

Returns

lang
'es' | 'en'
Language code from URL, or default language if not found

Usage Example

import { getLangFromUrl } from './i18n/utils';

// In an Astro component
const lang = getLangFromUrl(Astro.url);
// URL: https://adosa.com/en/properties -> returns 'en'
// URL: https://adosa.com/propiedades -> returns 'es'

useTranslations()

Returns a translation function for the specified language.
function useTranslations(lang: keyof typeof ui): (key: keyof typeof ui[typeof defaultLang]) => string

Parameters

lang
'es' | 'en'
required
Language code to use for translations

Returns

t
function
Translation function that accepts a key and returns the translated string. Falls back to default language if translation is missing.

Usage Example

import { useTranslations } from './i18n/utils';

const lang = 'en';
const t = useTranslations(lang);

console.log(t('nav.home'));       // "About Adosa"
console.log(t('nav.properties')); // "Properties"
console.log(t('grid.featured'));  // "FEATURED"

In Astro Components

---
import { getLangFromUrl, useTranslations } from '../i18n/utils';

const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang);
---

<nav>
  <a href="/">{t('nav.home')}</a>
  <a href="/properties">{t('nav.properties')}</a>
  <a href="/contact">{t('nav.contact')}</a>
</nav>

useTranslatedPath()

Returns a function that creates language-prefixed URLs.
function useTranslatedPath(lang: keyof typeof ui): (path: string, l?: string) => string

Parameters

lang
'es' | 'en'
required
Current language code

Returns

translatePath
function
Function that accepts a path and optional language code, returning the properly prefixed URL. Default language paths have no prefix.

Usage Example

import { useTranslatedPath } from './i18n/utils';

const translatePath = useTranslatedPath('en');

translatePath('/properties');        // "/en/properties"
translatePath('/contact');           // "/en/contact"
translatePath('/properties', 'es');  // "/properties" (default lang, no prefix)
translatePath('/properties', 'en');  // "/en/properties"

In Language Switcher

---
import { getLangFromUrl, useTranslatedPath } from '../i18n/utils';

const lang = getLangFromUrl(Astro.url);
const translatePath = useTranslatedPath(lang);
const currentPath = Astro.url.pathname.replace(/^\/en/, '');
---

<div class="language-switcher">
  <a href={translatePath(currentPath, 'es')}>ES</a>
  <a href={translatePath(currentPath, 'en')}>EN</a>
</div>

getStaticPaths()

Helper function for generating static paths in Astro with language support.
function getStaticPaths(): Array<{ params: { lang: undefined | string } }>

Returns

paths
Array
Array of path configurations for Astro static generation:
  • { params: { lang: undefined } } - Default language (Spanish)
  • { params: { lang: 'en' } } - English language

Usage in Astro Pages

---
// src/pages/[lang]/properties.astro
import { getStaticPaths as getI18nPaths } from '../../i18n/utils';

export function getStaticPaths() {
  return getI18nPaths();
}

const { lang } = Astro.params;
---

Complete Example

---
// src/components/PropertyCard.astro
import { getLangFromUrl, useTranslations } from '../i18n/utils';
import type { Property } from '../data/properties';

interface Props {
  property: Property;
}

const { property } = Astro.props;
const lang = getLangFromUrl(Astro.url);
const t = useTranslations(lang);
---

<div class="property-card">
  <img src={property.image} alt={property.title} />
  
  <h3>{property.title}</h3>
  <p>{property.location}</p>
  
  {property.status === 'DESTACADO' && (
    <span class="badge">{t('grid.featured')}</span>
  )}
  
  <div class="details">
    <span>{property.bedrooms} {t('grid.bed_unit')}</span>
    <span>{property.bathrooms} {t('grid.bath_unit')}</span>
    <span>{property.size}</span>
  </div>
  
  <div class="price">
    <strong>{t('property.price')}:</strong> {property.price}
  </div>
</div>

Source Locations

  • src/i18n/ui.ts:1-106 - Translation keys and language configuration
  • src/i18n/utils.ts:1-27 - Utility functions

Build docs developers (and LLMs) love