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

docs: Clarify config for custom interpolation suffix/prefix #1681

Merged
merged 2 commits into from
Feb 13, 2022

Conversation

joostdecock
Copy link
Contributor

It took me a while to figure out how to get a custom interpolation prefix/suffix to work.

I think it's a little unintuitive that changing an option that relates to how the text inside the translation files is structured has a knock-on effect to how files are loaded. That is not criticism, I realize it's because of how the various packages interact, but it's still a bit of a head-scratcher.

After doing some digging, I came across #1090 that clarifies the issue, but I feel it's worth putting this in the README.

This PR does that. It's not much, but I hope you find it useful.

It took me a while to figure out how to get a custom
interpolation prefix/suffix to work.

I think it's a little unintuitive that changing an option
that relates to how the text inside the translation files
is structured has a knock-on effect to how files are loaded.

After doing some digging, I came across i18next#1090 that clarifies
the issue, but I feel it's worth putting this in the README.

This PR does that. It's not much, but I hope you find it useful.
@vercel
Copy link

vercel bot commented Feb 10, 2022

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/9tQx5MeS2KipzPad5ofykD2Lc16u
✅ Preview: https://next-i18next-git-fork-joostdecock-master-isaachinman.vercel.app

@isaachinman
Copy link
Contributor

Hey @joostdecock#1248 was supposed to fix this issue, and localeStructure should respect the interpolation options. Are you saying you've noticed a regression in that regard?

@joostdecock
Copy link
Contributor Author

It works, but only if you (also) add the localeStructure setting.
If my reading of #1248 is correct, that is also what is supposed to happen (as in, the example clearly sets the localeStructure setting.

This example lifted from #1248 will work as-is:

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

But removing the localeStructure setting will make this not work:

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

So it's easy enough to get it to work if you know that you must set localeStructure to match your custom prefix/suffix.
I found that confusing at first since the prefix/suffix setting relates to how placeholders for interpolation are escaped inside your data. So it's not really obvious that this has a knock-on effect on locating the files themselves.

So I felt some clarification would be best.
I hope I'm managing to explain myself 😂

@isaachinman
Copy link
Contributor

Yep, makes sense, and thanks for a detailed explanation. In the end, these are just raw, user-config strings, and it wouldn't be possible to detect and swap custom prefix/suffix values.

Happy to merge this, thanks very much for your contribution!

@isaachinman isaachinman merged commit 5fff8de into i18next:master Feb 13, 2022
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.

2 participants