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.

Support formatting in Interpolate component

See original GitHub issue

Could you please add support for i18next formatting in Interpolate component?

Initial settings:

import i18n from 'i18next';
import XHR from 'i18next-xhr-backend';
import moment from 'moment';

i18n.use(XHR)
.init({
  fallbackLng: 'en',
  ns: ['common'],
  defaultNS: 'common',
  debug: true,
  interpolation: {
    format: function(value, format, lng) {
      if(value instanceof Date) return moment(value).format(format);
      return value;
    }
  }
});

common.json:

{
  "copyright":"© {{date, YYYY}}. {{link}} - All rights reserved"
}

and component:

<Interpolate i18nKey="copyright" useDangerouslySetInnerHTML date={new Date()} link={<a href="http://company" target="blank">Company</a>}/>

result is warning: i18next: interpolator: missed to pass in variable date, YYYY for interpolating &copy; {{date,YYYY}}. {{link}} - All rights reserved

Thank you

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
jamuhlcommented, Feb 2, 2018

the links are over a year old…the new samples have no use of the Interpolate anylonger…as more or less that component is replaced by Trans component: https://react.i18next.com/components/trans-component.html

1reaction
parulMilttalcommented, Feb 28, 2019

That I have changed while pasting the code in forum, Issue is not with this. My problem is format function is not excecuting.

On Thu, 28 Feb 2019 at 5:58 PM, Jan Mühlemann notifications@github.com wrote:

{{locationName, bold}} -> where did you define the format bold? i only see uppercase

format(value, format) { if (format === “uppercase”) { return value.toUpperCase(); } return value; }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/i18next/react-i18next/issues/229#issuecomment-468254826, or mute the thread https://github.com/notifications/unsubscribe-auth/AcZJBsoSsZGfVWPRl9fqxiMXv8fPMf0bks5vR8tugaJpZM4L3h8e .

Read more comments on GitHub >

github_iconTop Results From Across the Web

string interpolation - format string output
A format string that is supported by the type of the expression result. For more information, see Format String Component. The following example ......
Read more >
Internationalization in React: Interpolation, Formatting and ...
In this blog, we will explore further on this aspect to include additional dynamicity and extra formatting to specific data types. Trans ...
Read more >
Interpolate (v9) - react-i18next documentation
The interpolate component enables you to interpolate react components into translation strings (eg. to use links). ... You can use formatting as in...
Read more >
Aligning strings within string.Format and interpolated strings
You can use alignment components in your format strings to both right-align and left-align your formatted values. This pads the formatted values ...
Read more >
Components | Format.JS
The components render React elements by building on React Intl's imperative API. ... Support rich-text string/message formatting in <FormattedMessage> .
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