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

customTransComponents not working #178

Open
hazem3500 opened this issue Nov 11, 2020 · 3 comments
Open

customTransComponents not working #178

hazem3500 opened this issue Nov 11, 2020 · 3 comments

Comments

@hazem3500
Copy link

Describe the bug
I've made a custom local Trans component then added the path to it in my .babelrc, but after running the extraction script the keys in the Trans component don't get extracted

How to reproduce

Babel configuration:

{
    "presets": ["next/babel"],
    "plugins": [
        [
            "i18next-extract",
            {
                "locales": ["en", "ar", "de", "fr", "pt"],
                "defaultNS": "common",
                "outputPath": "public/static/locales/{{locale}}/{{ns}}.json",
                "enableExperimentalIcu": true,
                "jsonSpace": 4,
                "useI18nextDefaultValue": true,
                "customUseTranslationHooks": [["./i18n", "useTranslation"]],
                "customTransComponents": [["./i18n", "Trans"]]
            }
        ]
    ]
}

Reproduction:

// component file
import { Trans } from '../i18n'

export default function Test() {
    return (
        <Trans i18nKey="text">
            hello <i>locale</i>
        </Trans>
    )
}
// i18n.tsx
import NextI18Next, { InitConfig } from 'next-i18next'
import path from 'path'

const I18nInstance = new NextI18Next({
    otherLanguages: ['ar'],
    localePath: path.resolve('./public/static/locales'),
} as InitConfig)

export const {
    appWithTranslation,
    Link,
    Router,
    Trans,
    config,
    i18n,
    initPromise,
    useTranslation,
    withTranslation,
} = I18nInstance

export default I18nInstance

Expected behavior

The keys in the Trans component should be extracted

What actually happens

The keys weren't extracted

Your environment

  • OS (e.g. ArchLinux): windows 10
  • Plugin version (e.g. 0.3.0): 0.8.2
  • Node version (e.g. 12.13.0): 14.8.0
@lelamk140
Copy link

Same issue, anyone resolved this or has some hints?

@quertenmont
Copy link

same for me. Would be nice to have it working!

@remimarsal
Copy link

In my case as I'm using TypeScript aliases, I solved it by providing the import name instead of the module path.

For example if you use
import { T } from "my-custom-components"

<T>text</T>

Then you would provide
customTransComponents: [["my-custom-components", 'T']]

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

No branches or pull requests

4 participants