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
Merged

Conversation

@brumeregan
Copy link
Contributor

brumeregan commented Mar 13, 2019

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

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor Author

brumeregan commented Mar 13, 2019

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

@jamuhl

This comment has been minimized.

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
0 of 3 checks passed
0 of 3 checks passed
ci/circleci: build Your tests failed on CircleCI
Details
codeclimate 2 issues to fix
Details
workflow Workflow: workflow
Details
@jamuhl

This comment has been minimized.

Copy link
Member

jamuhl commented Mar 14, 2019

Was published in react-i18next@10.5.0

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

This comment has been minimized.

Copy link
Contributor Author

brumeregan commented Mar 14, 2019

thanks!! =)

@jamuhl

This comment has been minimized.

Copy link
Member

jamuhl commented Mar 14, 2019

Thank you for providing this PR...

@jamuhl

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.