Nuxt Setup
Quick setup guide for Nuxt applications with Stringer CLI
Stringer CLI integrates with Nuxt using the official @nuxtjs/i18n module.
Default Routing: By default, Stringer uses the no_prefix strategy — URLs won't have locale prefixes (e.g., /about instead of /en-us/about). For SEO-friendly URL prefixes, see URL-based i18n Routing.
Quick Start
Stringer detects Nuxt and sets up everything automatically. Follow the prompts to convert your files and select target languages.
What Stringer Does
When you run stringer in a Nuxt project:
- Installs @nuxtjs/i18n with the correct version for your Nuxt version
- Creates locale detection in
i18n/localeDetector.ts - Updates nuxt.config.ts with i18n configuration
- Converts your components — replaces text with
t('key')calls - Generates locale files with your translations
Code Transformation
Components and Pages
Server API Routes
What's Converted
Converted:
- Text in templates and pages
- Strings in
<script setup>that are user-facing - Strings inside
defineEventHandleron server routes
Not converted:
- Code comments
- Console logs and debug messages
- Content inside
<style>tags - Strings in
/composablesfolder
About Composables: Strings in /composables are skipped. Depending on whether a composable runs client-side or server-side, injected t() calls may cause errors. Keep user-facing strings in components, pages, or inside defineEventHandler scope.
Server-Side Translation
Inside Event Handlers
Stringer converts strings inside defineEventHandler:
Outside Event Handlers
Strings outside the event handler are not converted. If you have helper functions with user-facing strings (like error messages), move them inside the handler:
Stringer ignores strings outside defineEventHandler in server routes because there's no event context to get translations from.
URL-based i18n Routing
Enable SEO-friendly locale prefixes in your URLs (e.g., /en-us/about, /fr-fr/about).
Enabling URL Routing
Option 1: During the convert flow, select "Enable URL-based routing"
Option 2: Run the command:
What Happens
When enabled, Stringer:
- Changes strategy in
nuxt.config.tsfromno_prefixtoprefix - Wraps internal links with
localePath()automatically - Creates middleware for locale redirects
- Installs SEO modules —
@nuxtjs/sitemapand@nuxtjs/robots - Configures sitemap — auto-generates multilingual XML sitemaps
- Configures robots.txt — includes sitemap reference for crawlers
Automatic SEO Setup
When URL routing is enabled, Stringer automatically installs and configures two additional modules for search engine optimization:
@nuxtjs/sitemap generates a multilingual sitemap at /sitemap.xml with:
- Locale-prefixed URLs for all your pages
hreflangannotations linking alternate language versions- Automatic exclusion of API routes and internal paths
@nuxtjs/robots generates robots.txt with:
- Reference to your sitemap for crawler discovery
- Default allow rules for search engines
The generated nuxt.config.ts will include:
Site URL Required: Ensure your nuxt.config.ts has a site.url configured for the sitemap to generate absolute URLs. Stringer uses your project's SITE_URL environment variable if available.
Link Wrapping
Stringer automatically wraps your internal links:
For any new links you add later, wrap them manually:
Fixing Routing Issues
If you experience 404 errors or infinite redirects after enabling URL routing:
Step 1: Try the repair flow
Step 2: If issues persist, check for middleware conflicts. Temporarily rename custom middleware files to identify conflicts.
Step 3: Ensure API routes and static assets are excluded from locale prefixing.
See Troubleshooting for more details.
Language Switching
Common Issues
Lists Not Updating on Language Change
Use computed for reactive translations:
Module Not Found
Locale Files Not Loading
Check your file structure matches the config:
Hydration Mismatches
Ensure consistent locale detection. Check i18n/localeDetector.ts uses the same logic server and client-side.
Need Help?
Next Steps
- Commands — CLI reference
- Configuration — Project settings
- Pricing — Usage details