Skip to content
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

add 'polyglotScope' prop to translated component. #36

Open
guillaumearm opened this issue Oct 11, 2016 · 4 comments
Open

add 'polyglotScope' prop to translated component. #36

guillaumearm opened this issue Oct 11, 2016 · 4 comments
Assignees
Milestone

Comments

@guillaumearm
Copy link
Collaborator

guillaumearm commented Oct 11, 2016

need #35.

can set a polyglotScope with a prop:

const TranslatedDummy = translate(Dummy);
// <TranslatedDummy polyglotScope="my.super.scope" />
@guillaumearm guillaumearm changed the title add defaultPolyglotScope and add polyglotScope to translated component. add 'polyglotScope' prop to translated component. Oct 11, 2016
@JalilArfaoui
Copy link
Contributor

What is the use case for this ?

@guillaumearm
Copy link
Collaborator Author

hmm, i will write an example for this soon.

@guillaumearm
Copy link
Collaborator Author

guillaumearm commented Oct 20, 2016

I think it's more dynamic using react props,
we can as well use translate({ defaultPolyglotScope: 'super.scope' }) according to #35.

here an example.

import React from 'react';
import { compose } from 'redux';
import { connect } from 'react-redux';
import { translate } from 'redux-polyglot/translate';
// soon : import translate from 'react-redux-polyglot';
import { getCurrentBiz } from '../selectors';

const DummyTitle = ({ p }) => <p>{ p.tc('title') }</p>

const connectTranslated = compose(
    connect(state => ({ polyglotScope: `catalog.${getCurrentBiz(state)}` }))
    translate(), // according to #48
);
const TranslatedDummyTitle = connectTranslated(DummyTitle);

// with this phrases loaded :
const phrases = {
    catalog: {
        hotel: {
            title: 'Hotel lists'
        },
        fly: {
            title: 'Fly lists'
        }
    }
};
// then, just simply render TranslatedDummyTitle without any props.

@guillaumearm guillaumearm added this to the v0.4 milestone Dec 6, 2016
@JalilArfaoui
Copy link
Contributor

I'm not convinced about the reality of use case in real life ... but why not

@guillaumearm guillaumearm modified the milestones: v1.0, v0.4 Jan 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants