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

Potential Bug - localeStructure config not working #904

Closed
sbue opened this issue Dec 28, 2020 · 1 comment · Fixed by #934
Closed

Potential Bug - localeStructure config not working #904

sbue opened this issue Dec 28, 2020 · 1 comment · Fixed by #934

Comments

@sbue
Copy link

sbue commented Dec 28, 2020

Describe the bug

I have changed the default value for localeStructure from {{lng}}/{{ns}} to be {{ns}}/{{lng}}. I find this neater for my use case (namespaces tend to be very long, I don't want to write them twice)

Here is my i18n.ts file

import NextI18Next from 'next-i18next'
import * as path from 'path'
import { I18NextContext } from '@/utils/types'

const NextI18NextInstance = new NextI18Next({
  defaultNS: `common`,
  defaultLanguage: `es`,
  localePath: path.resolve(`public/static/translations`),
  otherLanguages: [`en`],
  fallbackLng: `en`,
  localeStructure: `{{ns}}/{{lng}}`,
})

export const { appWithTranslation, withTranslation } = NextI18NextInstance

Here is the error I am getting

error - Error: Default namespace not found at /my-project/public/static/translations/es/common.json
    at createConfig (/my-project/node_modules/next-i18next/dist/commonjs/config/create-config.js:117:19)
    at new NextI18Next (/my-project/node_modules/next-i18next/dist/commonjs/index.js:57:48)
    at eval (webpack-internal:///./src/utils/i18n.ts:11:29)
    at Module../src/utils/i18n.ts (/my-project/.next/server/pages/_app.js:856:1)
    at __webpack_require__ (/my-project/.next/server/pages/_app.js:23:31)
    at eval (webpack-internal:///./src/pages/_app.tsx:18:70)
    at Module../src/pages/_app.tsx (/my-project/.next/server/pages/_app.js:678:1)
    at __webpack_require__ (/my-project/.next/server/pages/_app.js:23:31)
    at Object.0 (/my-project/.next/server/pages/_app.js:891:18)
    at __webpack_require__ (/my-project/.next/server/pages/_app.js:23:31)

Occurs in next-i18next version

7.0.1

Steps to reproduce

Use the same config as my own

Expected behaviour

I would have expected the default namespace to be as such: public/static/translations/common/es.json

@isaachinman
Copy link
Contributor

Yep, looks like the logic here just needs to be updated to use localeStructure instead of /${defaultLanguage}/${combinedConfig.defaultNS}. PRs welcome!

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

Successfully merging a pull request may close this issue.

2 participants