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

Adding support for nested component inside Trans #784

Merged
merged 3 commits into from
Mar 14, 2019

Conversation

brumeregan
Copy link
Contributor

Hi,
Please consider my PR for improve functionality of react-i18next.

  • added support for nested components, like dynamic lists just on place in Trans component
    For now to include, for example, <ul> with several <li> we need to create additional Component and it makes supporting of code much more complicated (several components within one file... looks like hell ).
    So with this PR now Trans works like this
    <Trans i18nKey="key" components={[<ul>{['one', 'two'].map((item) => <li>{item}</li>}</ul>]} >

  • added support for values from translation message.
    Another issue that really annoying me that for components we need to provide some value.
    for now:
    <Trans i18nKey="test" values={{v: 'some value'}} components={[<span>{''}</span>]} />
    I propose additional format:
    <Trans i18nKey="test" values={{v: 'some value'}} components={[<span />]} />
    and translation message will be without changes:
    "test": "some message <0>{{v}}</0>"

… support for values from translation message
@jamuhl
Copy link
Member

jamuhl commented Mar 13, 2019

Does this also support:

<Trans i18nKey="key">My List:<ul>{['one', 'two'].map((item) => <li>{item}</li>}</ul></Trans>

@brumeregan
Copy link
Contributor Author

brumeregan commented Mar 13, 2019

@jamuhl yes, but in translation message it should be like:
"key": "result list: <1></1>"
Also add test for this case

@brumeregan
Copy link
Contributor Author

can anybody help with failing builds?
2 failing tests also fails in master
and not sure about codeclimate issue..

@jamuhl
Copy link
Member

jamuhl commented Mar 13, 2019

Will need to check tomorrow...can't make much out of the error message

@jamuhl jamuhl merged commit 3814af2 into i18next:master Mar 14, 2019
@jamuhl
Copy link
Member

jamuhl commented Mar 14, 2019

Was published in [email protected]

I also added the i18nIsDynamicList prop you can set on parent so the nodeToStrings creates the correct translation string for saveMissing: e0e140c#diff-3f70de7c1ba388c739ba6409eaaca576R528

<ul i18nIsDynamicList>{['a', 'b'].map(item => ( <li key={item}>{item}</li> ))}</ul>

@brumeregan
Copy link
Contributor Author

thanks!! =)

@jamuhl
Copy link
Member

jamuhl commented Mar 14, 2019

Thank you for providing this PR...

@jamuhl
Copy link
Member

jamuhl commented Mar 14, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants