question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Interpolation in combination with returnObjects does not work

See original GitHub issue

Describe the bug

Interpolation in combination with returnObjects does not work, because the placeholder is not replaced.

Occurs in react-i18next version

{
  "i18next": "^19.4.4",
  "i18next-xhr-backend": "^3.2.2",
  "react-i18next": "^11.4.0"
}

To Reproduce

{
  "requirements": [
    "Lorem Ipsum",
    "Lorem Ipsum",
    "Hello {{name}}"
  ]
}
const Test = ({ t }) => (
  <ul>
    {t('requirements', { returnObjects: true, name: 'Elon' }).map((r) => <li key={r}>{r}</li>)}
  </ui>
)

export default withTranslation()(Test)

Expected behaviour

[
  "Lorem Ipsum",
  "Lorem Ipsum",
  "Hello Elon"
]

instead of

[
  "Lorem Ipsum",
  "Lorem Ipsum",
  "Hello {{name}}"
]

OS:

  • Device: MacBook Pro 13" (2017) with macOS 10.15.3
  • Browser: Chrome 81.0.4044.129

Additional context

If I use joinArrays instead of returnObjects the interpolation works.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
adraicommented, May 4, 2020

try to set keySeparator to ‘.’, or just not false

0reactions
adraicommented, May 4, 2020

If you like this module don’t forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project.
 If you liked my support / work - I would enjoy a coffee sponsored using the “💜Sponsor Button”.
 There are many ways to help this project 🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

Objects and Arrays - i18next documentation
You can return objects or arrays to be used by third party modules localization: · keys · sample · The returned value supports...
Read more >
Translation features - i18next
Hint 1: You can change pre-/suffix by setting options on init or on calling t function with options: interpolationPrefix = '__',; interpolationSuffix =...
Read more >
i18next interpolation on nested data not displaying content of ...
You need to define a format function: https://www.i18next.com/translation-function/formatting#legacy-format-function-i18next-less-than-21.3.
Read more >
Mastering Multiple Language Support in React Native: Part 3
t("funnyLoadingMessages", { returnObjects: true });. You can apply interpolation and pluralization on the return as well. REFERENCING OTHER KEYS
Read more >
View Raw - UNPKG
FormatFunction; /** * Used to separate format from interpolation value * @default ' ... Helps finding issues with loading not working.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found