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

fix: Respect user-defined prefix/suffix when looking for default NS #1248

Merged

Conversation

alexmchardy
Copy link
Contributor

Fixes #1090 by respecting any custom interpolation.prefix and interpolation.suffix while using localeStructure to see if the default namespace file exists.

Can be tested by changing /examples/simple/next-i18next.config.js to

module.exports = {
  i18n: {
    defaultLocale: 'en',
    locales: ['en', 'de'],
  },
  interpolation: {
    prefix: '%{',
    suffix: '}',
  },
  localeStructure: '%{lng}/%{ns}',
}

Before the change, this config would result in this error:

Error: Default namespace not found at public/locales/%{lng}/%{ns}.json

After the change, the error goes away and interpolations work as expected. (To verify that interpolations work, you need to change /examples/simple/public/locales/en/common.json to use the %{ } prefix and suffix.)

@vercel
Copy link

vercel bot commented Jun 8, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/isaachinman/next-i18next/CXhxjreU86jWiy4rE2xbhf3sZ33v
✅ Preview: https://next-i18next-git-fork-alexmchardy-fix-locals-f439ba-isaachinman.vercel.app

@alexmchardy alexmchardy changed the title Respect user-defined prefix/suffix when looking for default NS fix: Respect user-defined prefix/suffix when looking for default NS Jun 8, 2021
@devan-huapaya
Copy link

Can this be merged? @isaachinman <3

@isaachinman
Copy link
Contributor

Hey @alexmchardy @devan-huapaya – sorry for the delay.

This PR looks great, it just needs test coverage. Thanks!

@devan-huapaya
Copy link

devan-huapaya commented Jul 7, 2021

No worries @isaachinman I'm just a random who was hoping to use the prefix setting!

I was able to get around the issue by wrapping useTranslation in it's own hook and adding
interpolation: { prefix: <prefix>, suffix: <suffix> } to all hook calls when options were passed in

@alexmchardy
Copy link
Contributor Author

@isaachinman added a test, hopefully looks good.

cc. @devan-huapaya

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 this pull request may close these issues.

LocaleStructure not compatibility single brackets for namespace
3 participants