question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why, in case of an error in the url, local translations are not loaded?

See original GitHub issue

Why, in case of an error in the url, local translations are not loaded?

My settings:

import i18n from 'i18next'
import ChainedBackend from 'i18next-chained-backend'
import Backend from 'i18next-http-backend'
import resourcesToBackend from 'i18next-resources-to-backend'
import { initReactI18next } from 'react-i18next'

import { currentLocale } from 'src/utils/helpers'

import resources from './src/translations/resources'

const options = {
  backends: [Backend, resourcesToBackend(resources)],
  backendOptions: [
    {
      loadPath: 'https://translation.rightwayhealthcare.com/{{lng}}.json',
      crossDomain: true,
    },
  ],
}

const customI18nextReactNative = () => ({
  init: Function.prototype,
  async: true,
  type: 'languageDetector',
  cacheUserLanguage: Function.prototype,
  detect: () => {
    if (currentLocale.match(/^en(.)*/)) {
      return 'en'
    }
    if (currentLocale.match(/es(.)*/)) {
      return 'es'
    }
    if (currentLocale.match(/ru(.)*/)) {
      return 'ru'
    }
    return 'en'
  },
})

i18n
  .use(ChainedBackend)
  .use(customI18nextReactNative())
  .use(initReactI18next)
  .init({
    getAsync: true,
    supportedLngs: ['en', 'es'],
    nonExplicitSupportedLngs: true,
    react: {
      useSuspense: false,
    },
    // debug: true,
    lng: currentLocale,
    backend: options,
    keySeparator: '.',
    fallbackLng: 'en',
    interpolation: {
      escapeValue: false,
    },
  })

export default i18n

example broken url:

loadPath: 'https://tran1slation.rightwayhealthcare.com/{{lng}}.json',

As I do in this case, the local translation should be connected, but it doesn’t.

Where am I going wrong?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
adraicommented, Sep 11, 2021

I noticed the “request” option, does that completely replace fetch with a custom function? If yes, I could utilize that to implement a client that works with react native debugger.

Yes

1reaction
adraicommented, Sep 7, 2021

Would it be reasonable to be able to opt-out of fetch API and use the XMLHttpRequest fallback only? @adrai

If I understood correctly this will never happen in a “productive” environment. It’s just a debug/dev issue. Can’t this be fixed at the root of the causing issue? react-native debugger?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React i18next fails to load translation after in build
I'm using the react build folder inside Django project. It works fine on localhost:3000 only which is crazy but once i try to...
Read more >
Common Errors with Exporting and Importing Translation Files
This error message only applies to data translation files. Data translation isn't enabled or was disabled after the data translation file was exported....
Read more >
Translations (Symfony Docs)
A catalog (e.g. big collection) of translated messages is loaded from translation resources defined for the locale (e.g. fr_FR ). Messages from the...
Read more >
Rails Internationalization (I18n) API - Ruby on Rails Guides
The translations load path (I18n.load_path) is just a Ruby Array of paths to your ... An URL like http://localhost:3001/nl will not work automatically, ......
Read more >
Translating React Apps with i18next | by Daniel Duan | Medium
In the case that a translation is not available in a certain language or the additional bundles do not load for whatever reason,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found