Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
calling another react component in my i18next file

I have below code.

import i18next from 'i18next';
import React from 'react';

const LanguageDetector = require('i18next-browser-languagedetector');
const initReactI18next = require('react-i18next');
import { TRANSLATIONS_EN } from '../public/locales/en/en.js';

i18next
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    resources: {
      en: TRANSLATIONS_EN,
    },
    fallbackLng: 'fr',
  });

i18next.changeLanguage(navigator.language);

export default i18next;

I am getting TRANSLATIONS_EN from a file. Now I need to get this value from API. so I created below componenet for testing.

import React from 'react';
import axios from 'axios';


 class TransFile extends React.Component {
      constructor() {
        super();
        alert('Mahima');
      }
    
      componentDidMount() {
        alert('Mahima');
          //API code .
      }
    
      render() {
        return <h2>Hi, I am a Mahima Saxena! + </h2>;
      }
    }
    export default TransFile;

when I am importing the above component in my i18 file and calling no output is coming.

import TransFile from './TransFile';

      <div>
        <TransFile />
      </div>;

I inserted above code in myi18next file but no output is coming. it is not even printing alert. Now my I18 file is below,

import i18next from 'i18next';
import React from 'react';

const LanguageDetector = require('i18next-browser-languagedetector');
const initReactI18next = require('react-i18next');

import { TRANSLATIONS_FR } from './../public/locales/fr/fr.js';
import { TRANSLATIONS_EN } from '../public/locales/en/en.js';
import { TRANSLATIONS_IT } from '../public/locales/it/it.js';
import { TRANSLATIONS_ES } from '../public/locales/es/es.js';
import TransFile from './TransFile';
//I Inserted below line
{
  <div>
    <TransFile />
  </div>;
}
i18next
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    resources: {
      en: TransFile,
      fr: TRANSLATIONS_FR,
      es: TRANSLATIONS_ES,
      it: TRANSLATIONS_IT,
    },
    fallbackLng: 'fr',
  });

i18next.changeLanguage(navigator.language);

export default i18next;

what mistake I am doing. basically I have to assign values from another component.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

https://www.i18next.com/overview/getting-started Create a simple structure like here and export it with export default. Note: Call the translation files by importing them yourself. If it is used outside of Component

import i18n from '../i18n';
i18n.t('test')
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda