Advanced Localization Guide
This guide provides comprehensive technical documentation for implementing localization in your Weaverse Hydrogen storefront, covering locale detection mechanisms, thelocale parameter, multi-project architectures, and best practices.
Overview
Weaverse provides flexible localization support through multiple detection methods and configuration options. Understanding these mechanisms helps you choose the right approach for your storefront’s needs.What You’ll Learn
- Locale format standards and conventions
- Three methods for locale detection and their priorities
- Using the
localeparameter inloadPage() - Locale fallback behavior and handling missing locales
- Multi-project architecture for advanced localization needs
- Best practices and troubleshooting
Locale Format Standards
Weaverse uses the standardlanguage-country format for locale identifiers.
Format Specification
Pattern:language-country (lowercase, hyphen-separated)
- Language code: ISO 639-1 (2-letter lowercase)
- Country code: ISO 3166-1 alpha-2 (2-letter lowercase)
- Separator: Hyphen (
-)
Common Examples
| Locale | Language | Country | Description |
|---|---|---|---|
en-us | English (en) | United States (us) | English in the United States |
en-gb | English (en) | United Kingdom (gb) | English in the United Kingdom |
fr-ca | French (fr) | Canada (ca) | French in Canada |
fr-fr | French (fr) | France (fr) | French in France |
sv-se | Swedish (sv) | Sweden (se) | Swedish in Sweden |
de-de | German (de) | Germany (de) | German in Germany |
ja-jp | Japanese (ja) | Japan (jp) | Japanese in Japan |
es-es | Spanish (es) | Spain (es) | Spanish in Spain |
es-mx | Spanish (es) | Mexico (mx) | Spanish in Mexico |
Important: Weaverse requires the exact lowercase hyphen-separated format. Formats like
en_US, en-US, or EN-us are not supported and may cause locale detection to fail.Locale Detection Methods
Weaverse provides three methods for detecting the current locale, with a clear priority order.Detection Priority
WhenloadPage() is called, Weaverse determines the locale using this priority:
- Explicit
localeparameter (highest priority) - Path prefix detection (deprecated, may be removed in future)
- Auto-detection from
context.storefront.i18n(default fallback)
Method 1: Explicit locale Parameter (Recommended)
The most reliable and recommended approach is to explicitly pass thelocale parameter to loadPage().
- You have custom routing logic that determines locale
- Loading content for a different locale than the current page
- Background jobs or server-side processes without request context
- Testing or previewing locale-specific content
- You want explicit control over locale selection
- Complete control over locale selection
- No ambiguity about which locale is being loaded
- Works in any context (routes, background jobs, utilities)
- Future-proof as other methods may be deprecated
Method 2: Path Prefix Detection (Deprecated)
Weaverse can extract locale from the URL path prefix.- Parses the first segment of the URL path
- Validates it matches the
language-countryformat - Uses it as the locale if valid
- Requires specific URL structure
- May conflict with custom routing
- Being phased out in favor of explicit parameters
Method 3: Auto-detection from context.storefront.i18n (Default)
When nolocale parameter is provided and path prefix detection fails, Weaverse reads locale from Hydrogen’s storefront context.
- Hydrogen storefront must be configured with i18n
context.storefront.i18n.pathPrefixmust be set- Theme schema must include i18n configuration
- Standard Hydrogen i18n setup
- URL structure matches Shopify’s locale routing
- No complex custom routing logic
Using the locale Parameter
Basic Usage
Dynamic Locale Selection
Cross-Locale Content Loading
Load content from multiple locales simultaneously:Locale Fallback Behavior
Understanding how Weaverse handles missing locales is important for reliable internationalization.Current Behavior
Current Implementation: If the requested locale doesn’t exist, Weaverse falls back to
en-us content.Planned Future Behavior
Planned fallback priority:- Exact locale match: Try requested locale (e.g.,
sv-se) - Language match: Try any locale with same language (e.g.,
sv-*) - Default locale: Use default from theme schema
- Final fallback: Use
en-usas last resort
Handling Fallback in Your Code
Single-Project Localization
How It Works
The standard approach uses one Weaverse project with theme schema i18n configuration:Limitations
While single-project localization works well for many use cases, it has some limitations:- No per-locale theme settings: Global theme settings (colors, fonts, layout options) apply to all locales
- URL structure constraints: Best with
url-pathstructure;subdomainandtop-level-domainhave limited support - Studio domain sync: No automatic domain-based locale switching in Studio
- Shared page structure: All locales share the same page routing and structure
When Single-Project Works Well
- Content translation is the primary need
- All markets use the same theme and branding
- URL structure follows path-based locales (
/en-us,/fr-ca) - Centralized content management is preferred
Multi-Project Architecture
For advanced localization needs and complex use cases, Weaverse supports a multi-project approach where each market, brand, or variant has its own dedicated project.Looking for comprehensive multi-project guidance? This section covers multi-project basics for localization. For complete documentation including A/B testing, multi-brand storefronts, advanced routing patterns, and step-by-step migration guides, see the Multi-Project Architecture Guide.
When to Use Multi-Project for Localization
Consider multi-project architecture for localization when you need:- Different theme settings per market: Unique colors, fonts, layouts for each locale
- Market-specific page structures: Different pages, navigation, or content organization
- Domain-based localization: Top-level domains (mystore.se, mystore.fr) or subdomains (se.mystore.com)
- Team isolation: Separate teams managing different market projects
Basic Setup Example
ConfigureWeaverseClient with a projectId function that determines which project to use based on domain:
Learn More
For comprehensive multi-project documentation, including:- A/B testing and experimentation - Traffic splitting, variant assignment, analytics
- Multi-brand storefronts - Subdomain routing, brand-specific themes
- Advanced routing patterns - Path-based, query parameter, header-based, and hybrid routing
- Complete Studio workflow - Project duplication, content management
- Step-by-step migration guide - Migrating from single to multi-project (6 phases)
- Performance optimization - Caching strategies, CDN configuration
- Troubleshooting - Common issues and solutions
Best Practices
Performance Considerations
Caching Strategies
Caching Strategies
Locale-specific caching:
Parallel Loading
Parallel Loading
Load Shopify and Weaverse data in parallel:
Minimize Cross-Locale Requests
Minimize Cross-Locale Requests
Only load additional locales when absolutely necessary:
Code Organization
Troubleshooting
Locale Not Detected Correctly
Symptoms:- Wrong locale content displayed
- Fallback to en-us when shouldn’t
- Locale detection inconsistent
Use Explicit locale Parameter
Use Explicit locale Parameter
Don’t rely on auto-detection. Explicitly pass the locale:
Verify Locale Format
Verify Locale Format
Ensure locale is lowercase with hyphen:
Check Theme Schema Configuration
Check Theme Schema Configuration
Verify theme schema i18n matches your locale:
Validate context.storefront.i18n
Validate context.storefront.i18n
Check that Hydrogen’s i18n is properly configured:
Fallback Behavior Unexpected
Problem: Page falls back to en-us when locale content should exist. Checklist:- Verify locale content exists in Weaverse Studio
- Check locale format matches exactly (lowercase, hyphen)
- Confirm page is published for that locale
- Test with explicit locale parameter to rule out detection issues
- Check browser console and network tab for errors
Multi-Project Routing Issues
Symptoms:- Wrong project content displayed
- Project switching not working
- projectId not being applied
Debug projectId Function
Debug projectId Function
Add logging to see which project is selected:
Verify Project IDs
Verify Project IDs
Ensure project IDs match exactly:
- Check Weaverse Studio for correct project ID
- Verify no typos in project ID strings
- Confirm WEAVERSE_PROJECT_ID environment variable if used
Test Route-Level Override
Test Route-Level Override
Try explicit projectId in loadPage to isolate issue:
Content Not Syncing Between Projects
Problem: Updates in one project don’t appear in other projects. Important: Each project is independent. Content must be manually synced using Weaverse’s import/export features. Workflow:- Export content from source project in Weaverse Studio
- Import into target project(s)
- Customize translated content as needed
- Repeat for each project requiring the update
Related Documentation
Markets & Localization
Studio workflow for creating localized pages
Rendering Pages
loadPage() usage and page rendering fundamentals
Custom Routing
Custom URL structures with localization
WeaverseClient API
Complete API reference for loadPage() and parameters
Summary
Weaverse provides flexible localization through:- Three detection methods with clear priority: explicit locale parameter (recommended), path prefix detection (deprecated), and auto-detection from context
- Standard locale format:
language-country(lowercase, hyphen-separated) - Fallback behavior: Currently defaults to en-us, smart fallback coming soon
- Two architectural approaches: Single-project for simpler needs, multi-project for advanced requirements
- Complete control: Explicit parameters provide full control over locale and project selection