martinandert / counterpart

A translation and localization library for Node.js and the browser.
MIT License
242 stars 25 forks source link

Passing react dom element to a placeholder #45

Closed beku8 closed 7 years ago

beku8 commented 7 years ago

We are using counterpart heavily and it would be great if we can pass react dom element to a placeholder like so

// imagine the following entry
counterpart.registerTranslations('en', {
 departures: {
      available_of: '%(available)s available of total %(max)s pax'
    }
})

// and display it using
  const available = (count) => {
    return (<b>{count}</b>);
  };
 translate('departures.available_of', {available: available(departure.available), max: departure.max})

Is it possible to implement this, please?

martinandert commented 7 years ago

Hi Bilguun, I think adding direct support for React to this package is out of its scope. But react-translate-component and react-interpolate-component should help you to accomplish your use case.

yanndinendal commented 7 years ago

@beku8 : Hi, it should also work with @gandi/react-translate, which also uses Counterpart: https://github.com/Gandi/react-translate/blob/master/doc/translator.md, if it can help.