Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page render breaks if translation file not included for all locales #1831

Open
adam-geipel opened this issue Feb 5, 2025 · 1 comment
Open

Comments

@adam-geipel
Copy link

🐛 Bug Report

When i18n is configured to use the resourcesToBackend feature such as with the provided config and the namespace files are not the same between languages, translations fail to be retrieved for the default language when referencing the file(s) with which there is a delta.

This results in the page becoming unresponsive and needing to be forcibly closed.

To Reproduce

Use this i18n configuration:

import { initReactI18next } from 'react-i18next';
import i18n from 'i18next';
import resourcesToBackend from 'i18next-resources-to-backend';
import LanguageDetector from 'i18next-browser-languagedetector';

const DEFAULT_LANGUAGE = 'en';
const DEFAULT_NAMESPACE = 'common';

i18n
  .use(
    resourcesToBackend(
      async (language: string, namespace: string) =>
        import(`./locales/${language}/${namespace}.json`)
    )
  )
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    ns: [DEFAULT_NAMESPACE],
    defaultNS: DEFAULT_NAMESPACE,
    debug: true,
    fallbackLng: DEFAULT_LANGUAGE,
    interpolation: {
      escapeValue: false
    }
  });

include a mis-matched set of JSON files across localizations:

locales
├── en
│   ├── addresses.json
│   ├── common.json
│   └── navigation.json
└── es
    ├── common.json
    └── navigation.json

when rendering a component that uses the addresses namespace in this instance, the useTranslation hook will not be able to identify the namespace file.

This results in an infinite loop in the useTranslation hook (somewhere), resulting in the webpage "freezing", becoming unresponsive until the browser tab is closed.

Expected behavior

The configured i18n instance is able to load all files independent of what is available for other languages, and supply the text value for the one of the following:

  1. the configured default language
  2. the browser's set language
  3. no translation, just use the placeholder text as if it couldn't be found normally

Your Environment

  • runtime version: node v22, any browser
  • i18next version: 24.2.1
  • i18next-resources-to-backend version: 1.2.1
  • os: Mac, linux kubernetes
@adrai
Copy link
Member

adrai commented Feb 5, 2025

I'm not able to reproduce your issue...
I get a correct warning in the console and the UI renders the fallback value:

Image

Please provide a minimal reproducible but complete example repository... not just code snippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants