Skip to main content

Troubleshooting Internationalization

This guide covers common issues you might encounter when using the internationalization package and provides solutions to resolve them.

Common Issues

Missing Translations

Symptoms

  • Text appears in the default language (English) instead of the selected language
  • Translation keys appear in the UI instead of translated text
  • Console warnings about missing translations

Solutions

  1. Check if the translation key exists Verify that the translation key exists in the dictionary file for the current locale:
  2. Add missing translations Add the missing translation to the appropriate dictionary file:
  3. Use fallback for optional translations For translations that might not exist in all locales, use optional chaining and fallbacks:
  4. Run the translation script Use the built-in translation script to generate missing translations:

Middleware Not Working

Symptoms

  • Locale is not detected correctly
  • URL-based locale switching doesn’t work
  • Always redirects to the default locale

Solutions

  1. Check middleware configuration Ensure your middleware.ts file is correctly configured:
  2. Verify matcher pattern Make sure the matcher pattern is correct and doesn’t exclude your routes:
  3. Check for conflicting middleware If you have other middleware, make sure they don’t conflict with the internationalization middleware:

Client Components Not Translating

Symptoms

  • Server components show correct translations, but client components don’t
  • Client components show translation keys instead of translated text
  • Errors related to the useTranslation hook

Solutions

  1. Check TranslationProvider setup Make sure your client components are wrapped with the TranslationProvider:
  2. Verify namespace parameter Check that you’re using the correct namespace in the useTranslation hook:
  3. Check for React context issues If you’re using multiple providers, make sure they’re not interfering with each other:

Language Switching Issues

Symptoms

  • Clicking language switcher links doesn’t change the language
  • URL changes but content doesn’t update
  • Language switcher links go to 404 pages

Solutions

  1. Check language switcher implementation Make sure your language switcher correctly builds the URLs:
  2. Verify route structure Ensure your routes are properly structured with the locale parameter:
  3. Check for caching issues If the URL changes but the content doesn’t update, it might be a caching issue:

Date and Number Formatting Issues

Symptoms

  • Dates and numbers are not formatted according to the locale
  • Formatting is inconsistent across the application

Solutions

  1. Use the Intl API consistently Make sure you’re using the Intl API for formatting:
  2. Create helper functions Create reusable helper functions for formatting:
  3. Handle locale-specific formats Be aware of locale-specific formats and handle them appropriately:

Debugging Techniques

Console Logging

Add console logs to track the flow of translations:

Browser Developer Tools

Use browser developer tools to inspect the React component tree and context values:
  1. Open your browser’s developer tools (F12 or right-click > Inspect)
  2. Go to the Components tab (in React DevTools)
  3. Find the TranslationProvider component
  4. Check its props (locale and messages)
  5. Look for any errors in the console

React DevTools

Install React DevTools for more detailed debugging:
Then use it to inspect your components:

Advanced Troubleshooting

Missing or Incorrect TypeScript Types

Symptoms

  • TypeScript errors related to translation types
  • No autocomplete for translation keys

Solutions

  1. Define proper types for your translations Create a type definition for your translations:
  2. Use type assertions with the useTranslation hook

Performance Issues

Symptoms

  • Slow page loads when switching languages
  • High memory usage

Solutions

  1. Optimize dictionary size Split large dictionaries into smaller chunks:
  2. Use code splitting Load translations only when needed:
  3. Memoize translation functions Use memoization to prevent unnecessary re-renders:

Common Error Messages and Solutions

Solution:Make sure the package is correctly installed and included in your dependencies:
Then run:
Solution:Add the missing translation key to all locale files:
Or use optional chaining and fallbacks:
Solution:Make sure your client component is wrapped with the TranslationProvider:
Check that you’re not using the hook in a Server Component:
Solution:Check that the dictionary file exists for the specified locale:
If it doesn’t exist, create it:
Then translate the content or run the translation script:

Getting Help

If you’re still experiencing issues after trying the solutions in this guide, you can:
  1. Check the documentation Review the other internationalization documentation pages for more information.
  2. Search for similar issues Look for similar issues in the project’s issue tracker or discussion forums.
  3. Ask for help Reach out to the team for assistance, providing:
    • A clear description of the issue
    • Steps to reproduce the problem
    • Error messages (if any)
    • Code samples demonstrating the issue

Next Steps

API Reference

Complete API reference for the internationalization package

Back to Introduction

Return to the internationalization introduction