-
-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Intl Proxy? Anyone? #636
Comments
Hey @Mensae, I used one in a project once. It's not polished but here is a minimalistic version extracted from that codebase: export default function createIntlProxy({ messages }) {
const IntlProxy = props => {
const { nextProxy, fixture: { locale = 'en' } } = props;
const { value: NextProxy, next } = nextProxy;
return (
<IntlProvider locale={locale} key={locale} messages={messages[locale]}>
<NextProxy {...props} nextProxy={next()} />
</IntlProvider>
);
};
return IntlProxy;
} Note:
Let me know if this works and if you're interested in making an official IntlProxy out of this. It would be a great addition to Cosmos! |
Thanks for sharing @skidding ! I'll try it out and let you know. |
Thanks ! Works like a charm :) |
@skidding I vote for adding this to react-cosmos officially! |
Added a link to the proxy above for now https://github.com/react-cosmos/react-cosmos/blob/master/README.md#more-proxies |
@skidding why will this proxy be published? or any documentation about the activation of this proxy? |
I'm putting all my time into Cosmos Next nowadays. But the proxy above seems to work for other people. It is always activated once you add it to your project and |
@sdgandhi thanks for your reply. That activation strategy seems not following what react-cosmos suggests in its doc:
any thoughts on this? Today is my day one using cosmos so trying to follow best practice as much as possible |
For those having the same concerns as mine, here's the modified version that supports opt-in activation: function createIntlProxy({ messages }) {
const IntlProxy = props => {
const { nextProxy, fixture: { intl } } = props;
const { value: NextProxy, next } = nextProxy;
const nextProxyEl = <NextProxy {...props} nextProxy={next()} />;
if (!intl) {
return nextProxyEl;
}
const { locale = 'en' } = intl;
return (
<IntlProvider locale={locale} key={locale} messages={messages[locale]}>
{nextProxyEl}
</IntlProvider>
);
};
return IntlProxy;
} To activate this proxy in a fixture, attribute // __fixtures__/fixture1.js
export default {
component: Component,
intl: true, // or an object can be passed to override the default locale e.g. intl: { locale: 'fr' }
} |
What's up?
As a first time traveler I am trying out Cosmos with React Boilerplate.
Now, just wondering if anyone made a proxy for React Intl?
Mkay, tell me more...
If there is none, yet, it'll be nice if there will be one, so I'll have a go at it.
The text was updated successfully, but these errors were encountered: