redux-polyglot icon indicating copy to clipboard operation
redux-polyglot copied to clipboard

add 'polyglotScope' prop to translated component.

Open guillaumearm opened this issue 9 years ago • 4 comments

need #35.

can set a polyglotScope with a prop:

const TranslatedDummy = translate(Dummy);
// <TranslatedDummy polyglotScope="my.super.scope" />

guillaumearm avatar Oct 11 '16 16:10 guillaumearm

What is the use case for this ?

JalilArfaoui avatar Oct 18 '16 21:10 JalilArfaoui

hmm, i will write an example for this soon.

guillaumearm avatar Oct 18 '16 22:10 guillaumearm

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 avatar Oct 20 '16 18:10 guillaumearm

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

JalilArfaoui avatar Dec 07 '16 00:12 JalilArfaoui