For the complete Netlify documentation index, see llms.txt. Markdown versions of any documentation page are available by appending .md to its URL. Back to templates
Set up a Netlify Edge Function that swaps prices, phone numbers, dates, and CTAs based on visitor country โ no API keys needed.
Using your project's framework and a Netlify Edge Function, set up country-based localization for this site.
Target countries: {{TARGET_COUNTRIES}}
Default country (defaults to US if not specified): {{DEFAULT_COUNTRY}}
The implementation should:
1. **Scan the site and mark localizable elements** in a single pass. Look for content that varies by country โ prices, currency symbols, phone numbers, date formats, physical addresses, and locale-specific CTAs. Add `data-localize="<key>"` attributes (e.g., `data-localize="pricing.monthly"`) to those elements in the HTML/templates.
2. **Create a localization config file** (e.g., `src/data/localization.json`) that maps country codes to localized values for each marked element. Pre-fill with correct values for each target country โ use real currency symbols, date formats, and phone number conventions. Structure it so adding a new country is just adding another key to the map.
3. **Create a Netlify Edge Function** that:
- Reads the visitor's country from `context.geo.country.code` (provided automatically by Netlify โ no API key needed)
- Loads the localization config
- Uses `HTMLRewriter` to find all elements with `data-localize` attributes and replace their content with the country-appropriate value
- Falls back to the default country for unrecognized or undetected countries
- Adds a `X-Geo-Country` response header for debugging
4. **Add the edge function configuration** to `netlify.toml`, scoped to all pages (`/*`).
Do not set any environment variables. Geo data is available automatically on Netlify's edge network.
Variables
The country to use as the fallback for visitors from unlisted countries. Defaults to US
he countries to localize for. Start with 2-3 key markets โ you can add more to the config later. Examples: US, GB, DE, FR, JP
Did you find this doc useful?
Your feedback helps us improve our docs.