Giter VIP home page Giter VIP logo

Comments (4)

bloodyowl avatar bloodyowl commented on August 10, 2024

Hi,

Yes, it's supposed to work on the server too. Do you have a minimal repro?

from react-translate.

mtt87 avatar mtt87 commented on August 10, 2024

😄 Yes npm i -g gatsby then gatsby new test-site then cd test-site

create gatsby-browser.js

import React from 'react';
import { TranslatorProvider } from "react-translate";
const translations = require('./i18n');

exports.wrapRootComponent = (Root) => {
  const Wrapper = () => (
    <TranslatorProvider translations={translations}>
      <Root />
    </TranslatorProvider>
  )
  return Wrapper;
}

create pages/home.js

import React from 'react';
const Home = ({ t }) => {
  return (
    <div>
      {t("tagline1")}
    </div>
  );
}
export default translate("Home")(Home);

then if you run gatsby develop and open your browser on localhost:8000/home everything should work fine
as soon as you run gatsby build the problem is that the context is lost and the translate('component')(component) doesn't work anymore, probably because there is no more ancestor <TranslatorProvider>

from react-translate.

mtt87 avatar mtt87 commented on August 10, 2024

gatsbyjs/gatsby#688 (comment)

Do you think it could it be related to this step?
https://github.com/gatsbyjs/gatsby/blob/b4d585a2c0035dc3c8896c42e2daaac1b520be5a/lib/utils/webpack.config.js#L137

case 'build-html':
  config.plugin('static-site-generator', StaticSiteGeneratorPlugin, ['render-page.js', routes])

Seems like you are adding manually routes torender-page.js otherwise it doesn't inherit them automatically from the context of react-router?

I was thinking if I have to do the same and pass the translator function created by the provider but at the moment I have no clear idea how all of this is working.

Could be related to the scope of static-site-generator-webpack?
https://github.com/markdalgleish/static-site-generator-webpack-plugin#scope

At this point I don't think it's related to your package because I get same error when using react-intl.

But if you wanna be nice and helpful I appreciate any hint to fix this.

from react-translate.

mtt87 avatar mtt87 commented on August 10, 2024

Almost solved
gatsbyjs/gatsby#688 (comment)

Not related to your library, I close the issue.

Thank you 😄

from react-translate.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.