stefalda / react-localization

Simple module to localize the React interface using the same syntax used in the ReactNativeLocalization module.
MIT License
373 stars 58 forks source link

Support localized functional component and JSX #115

Open hanayashiki opened 3 years ago

hanayashiki commented 3 years ago

In some context, it is necessary for us to localize not only strings but also components/JSX

let Strings = new LocalizedStrings({
 en: {
    "pay": (
       <Paypal />
    ),
    "link": (
       ({ name }) => (
         <a>{name}</a>
       )
    )
 },
 cn: {
    "pay": (
       <Alipay />
    ),
    "link": (
       ({ name }) => (
         <a><img alt={name} src="..." /></a>
       )
    )
 },
});

To use them:

return (
  <div>
    {Strings.pay}
    <Strings.link name={"114514"} />
  </div>
);
hanayashiki commented 3 years ago

Basically we might want to localize any type

It seems it is currently supported, but not listed in the documentation