gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.
https://i18next-extract.netlify.com
MIT License
161 stars 37 forks source link

customTransComponents not working #178

Open hazem3500 opened 4 years ago

hazem3500 commented 4 years ago

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

lelamk140 commented 2 years ago

Same issue, anyone resolved this or has some hints?

quertenmont commented 1 year ago

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

remimarsal commented 1 year ago

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']]