Comments (4)
Hi,
Yes, it's supposed to work on the server too. Do you have a minimal repro?
from react-translate.
😄 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.
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.
Almost solved
gatsbyjs/gatsby#688 (comment)
Not related to your library, I close the issue.
Thank you 😄
from react-translate.
Related Issues (14)
- Full usage example? HOT 2
- Helper to access translations outside components
- PropTypes is undefined HOT 1
- Locale identification and usage HOT 5
- Forwarding refs HOT 1
- Add ability to use ReactElements as variables in translations HOT 3
- Updating translations on the fly HOT 5
- Typo on NPM.com for under yarn add instructions
- Re-using translations HOT 3
- Namespaces / Nested translation keys HOT 9
- There are peerDependency issues! HOT 1
- react-translate with latest react release
- Can't make this work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-translate.