Make sure locales are configured first. See Setting Up Locales.
Fetching localized content via API
After enabling Localization, you will need to update all API calls to include the locale parameter. Thelocale parameter tells the ButterCMS API which localized version of your content to return.
API endpoint patterns
Single Page
Multiple Pages
Page Types
Collections
JavaScript / Node.js examples
Basic setup
Fetching a single Page
Fetching multiple Pages
Fetching Collections
Dynamic locale selection
Python examples
Basic setup
Fetching a single Page
Fetching multiple Pages
Fetching Collections
PHP / Laravel examples
Controller setup
Fetching Collections
Ruby / Rails examples
Basic setup
Fetching a single Page
Fetching Collections
cURL examples
Fetch single Page
Fetch multiple Pages
Fetch Collections
Next.js App Router example
Dynamic locale routing
Handling locale in frontend frameworks
Next.js internationalized routing
Configurenext.config.js for locale support:
Previewing localized content
Use thepreview parameter to fetch unpublished (draft) content in a specific locale.
Preview mode
To preview unpublished localized content, include thepreview parameter:
Setting up preview URLs
Configure locale-specific preview URLs in your frontend:Handling missing locale content
When content doesn’t exist in a requested locale, you have several options:Option 1: fallback to default locale
Option 2: show locale not available message
Option 3: redirect to available locale
Best practices
Error handling
Always handle cases where content might not exist in a requested locale:Caching considerations
- Cache responses per locale
- Invalidate cache when content is updated
- Consider using ISR (Incremental Static Regeneration) in Next.js
Performance tips
- Use the
fieldsparameter to request only needed fields - Implement pagination for large collections
- Pre-fetch content for common locale switches