Skip to content

Incosistent behaviour of Trans and t. Trans set defaultValue when t call doesn't set the field. #1876

@dbadura

Description

@dbadura

🐛 Bug Report

When I used Trans instead of t, the missingKeyHandler will have field defaultValue set in opts objects. Which makes hunting the real missing keys much harder.

To Reproduce

https://codesandbox.io/p/sandbox/i18next-react-problem-cgm87w
and please look at the warning logs.
The t call doesn't have defaultValue set in opts, but Trans` components fills this field.

            missingKeyHandler: (_lngs, _ns, key, fallback, _, opts) => {
                console.warn(
                    'Missing translation key:',
                    key,
                    'Fallback value:',
                    fallback,
                    opts,
                );
            }
                <Trans i18nKey={'missing-key-TRANS'}/>
                <Trans i18nKey={'missing-key-default-TRANS'} defaults={'Default_Value-TRANS'}/>
                <p>{t('missing-key')}</p>
                <p>{t('missing-key-default', {defalutValue: 'Default_Value'})}</p>

Expected behavior

The field defaultValue will have the same value as calling t

Your Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions