Skip to content

Commit

Permalink
Merge pull request #80 from everydayhero/fix/mapTranslationsToProps-r…
Browse files Browse the repository at this point in the history
…egression

Fix regression with custom `mapTranslationToProps` behaviour
  • Loading branch information
HowlingEverett authored Mar 6, 2018
2 parents 9d950a5 + 2cd1c9c commit bc27ea9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/translated-components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const translated = ({
locale: props.locale || locale || defaultLocale,
defaultLocale,
reducer: templateReducer(templateParamValues(props, params))
}))}
}), props)}
/>
)
}}
Expand Down
27 changes: 27 additions & 0 deletions packages/translated-components/test/translated-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,31 @@ describe('Translate', () => {

assert(wrapper.text().includes(translations['en_AU'].two))
})

it('should execute a custom mapTranslationsToProps to provide interpolated translations, if it exists', () => {
const translations = {
en_AU: {
one: 'AUOne',
two: 'AUTwo'
},
en_NZ: {
one: 'NZOne'
}
}
const mapTranslationsToProps = (translations, props) => {
return {
...translations,
three: props.three + ' Extra info!'
}
}
const Dummy = (props) => <div>{props.one}{props.two}{props.three}</div>
const DummyTranslated = translated({translations, mapTranslationsToProps})(Dummy)
const wrapper = mount(
<LocaleProvider locale='en_NZ' defaultLocale='en_AU'>
<DummyTranslated three='Three' />
</LocaleProvider>
)

assert(wrapper.text().includes('Three Extra info!'))
})
})

0 comments on commit bc27ea9

Please sign in to comment.