Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda