You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As of fluent-react 0.4.1 it is possible to pass React elements as props to <Localized> to interpolate them into the translation:
<Localizedid="sign-in-or-cancel"$signInButton={<Localizedid="sign-in-button"><buttonclassName="action"onClick={signIn}>{'Sign in'}</button></Localized>}$cancelButton={<Localizedid="cancel-button"><buttonclassName="text"onClick={cancel}>{'cancel'}</button></Localized>}><p>{'{ $signInButton } or { $cancelButton}.'}</p></Localized>
sign-in-button = Sign in
cancel-button = cancel
sign-in-or-cancel = { $signInButton } or { $cancelButton }.
This is a bad localization practice because it results in the translation being split into multiple strings and then interpolated.
Instead we should do something similar to fluent-dom's overlay logic.
Solution
With overlays, the translation can include some HTML which will be parsed by Fluent. HTML children found in the translation are then matched against child elements in the source. In React, we can pass the source elements via props.
<Localizedid="sign-in-or-cancel"button={<buttonclassName="action"onClick={signIn}></button>}a={<buttonclassName="text"onClick={cancel}></button>}><p>{'<button>Sign in</button> or <a>cancel</a>.'}</p></Localized>
sign-in-or-cancel = <button>Sign in</button> or <a>cancel</a>.
The text was updated successfully, but these errors were encountered:
This was fixed in #101 and then a few follow-ups landed in #105, #141, #154 and #155. I continued to use this issue to track overlay-related features. I'm now closing it for good and I'll be using the overlay label for the same purpose.
As of
fluent-react
0.4.1 it is possible to pass React elements as props to<Localized>
to interpolate them into the translation:This is a bad localization practice because it results in the translation being split into multiple strings and then interpolated.
Instead we should do something similar to
fluent-dom
's overlay logic.Solution
With overlays, the translation can include some HTML which will be parsed by Fluent. HTML children found in the translation are then matched against child elements in the source. In React, we can pass the source elements via props.
sign-in-or-cancel = <button>Sign in</button> or <a>cancel</a>.
The text was updated successfully, but these errors were encountered: