最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

next.js - react-i18next - new localization namespace not recognized as parameter for useTranslation - Stack Overflow

programmeradmin1浏览0评论

I'm currently extending a storefront that uses next.js, but I can't find out how to add a translation namespace that is recognized by react-i18next. The shop already had a next.i18next.conf.js file, where I added my namespace (customization):

module.exports = {
    i18n: {
        defaultLocale: 'de',
        locales: ['en', 'de', 'pl'],
        returnObjects: true,
        fallbackLng: 'de'
    },
    defaultNS: 'common',
    ns: ['common', 'homepage', 'checkout', 'customer', 'products', 'collections', 'customization'],
    localeStructure: '{{lng}}/{{ns}}',
    debug: process.env.NODE_ENV === 'development',
    /** To avoid issues when deploying to some paas (vercel...) */
    localePath: typeof window === 'undefined' ? require('path').resolve('./public/locales') : '/locales',

    reloadOnPrerender: process.env.NODE_ENV === 'development',
    interpolation: {
        escapeValue: false
    }
};

But when I try using it with useTranslation:

const { t } = useTranslation('customization');

I get this error:

Argument of type '"customization"' is not assignable to parameter of type '"common" | "homepage" | "checkout" | "customer" | "products" | "collections" | $Tuple<"common" | "homepage" | "checkout" | "customer" | "products" | "collections"> | undefined'.

How can I make react-i18next recognize the new namespace? The json file is aready present in the correct localization directory and I couldnt find any other place in the whole project where these types are defined. Can anyone help?

发布评论

评论列表(0)

  1. 暂无评论