Tiqa / redux-polyglot

Polyglot.js bindings for Redux
MIT License
58 stars 13 forks source link

Overwrite phrases #85

Closed ShakurOo closed 7 years ago

ShakurOo commented 7 years ago

Readme :

Overwrite phrases

In some case, you should be able to replace some default phrases by others phrases.

For doing this, you have to define an object which contains your overwrited phrases. This object is composed of : { 'some.nested.data': 'phrase', ... } where key is the target path you want to replace and value ... the new value.

with getP() selector

Add simply ownPhrases property and set the new configuration like above to overwrite :

store.dispatch(setLanguage('en', {
    some: { nested: { data: { hello: 'hello' } } }
}));
const p = getP(store.getState(), {
    polyglotScope: 'some.nested.data', 
    ownPhrases: { 'some.nested.data.hello': 'Hi !' }
});
console.log(p.tc('hello')) // => will return 'Hi !'
with translate() enhancer

Instead passing only string as parameter : translate('catalog', Dummy), pass a plain object which contains polyglotScope and ownPhrases properties :

translate({ 
    polyglotScope : 'some.nested.data', 
    ownPhrases: { 'some.nested.data.catalog': 'Cars' } 
}, Dummy);
console.log(p.tc('catalog')) // => will return 'Cars'
guillaumearm commented 7 years ago

It's ok for me. Thank you for contributing :-)

guillaumearm commented 7 years ago

@ShakurOo, Can you fix the last linting error ? You can use npm run lint ;-)

guillaumearm commented 7 years ago

So are we OK for this PR ?

JalilArfaoui commented 7 years ago

Yes ! I wan running tests (OK) and I just merged it ! Can you publish a new version ?

guillaumearm commented 7 years ago

@JalilArfaoui, @ShakurOo redux-polyglot@0.6 released on @latest npm dist-tag

Thanks you for contributing :-)