Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM fragments localization for fluent-react #103

Closed
stasm opened this issue Dec 10, 2017 · 1 comment
Closed

DOM fragments localization for fluent-react #103

stasm opened this issue Dec 10, 2017 · 1 comment

Comments

@stasm
Copy link
Contributor

stasm commented Dec 10, 2017

As of fluent-react 0.4.1 it is possible to pass React elements as props to <Localized> to interpolate them into the translation:

<Localized
    id="sign-in-or-cancel"
    $signInButton={
        <Localized id="sign-in-button">
            <button className="action" onClick={signIn}>{'Sign in'}</button>
        </Localized>
    }
    $cancelButton={
        <Localized id="cancel-button">
            <button className="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.

<Localized
    id="sign-in-or-cancel"
    button={
        <button className="action" onClick={signIn}></button>
    }
    a={
        <button className="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>.
@stasm
Copy link
Contributor Author

stasm commented Apr 16, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant