Skip to content

Would appreciate more detailed documentation for <Localized> #571

Open

Description

@mstange

I would appreciate some documentation for <Localized> that goes more into specifics. I'm reading https://github.com/projectfluent/fluent.js/wiki/Localized but it's not really answering most of my questions:

  • How deep does the replacement magic go? Obviously <Localized>Some string</Localized> works, and so does <Localized><div>Some string</div></Localized>, but how deep does it go?
  • Which part of the react children gets replaced by the localized contents? Does it only replace raw strings, and are all "element" descendants preserved, or can it happen that an element descendant gets "localized away"?
  • What happens if I have multiple raw strings inside the <Localized> contents, in different descendant elements?
  • Can <Localized> components be nested? What happens if I nest them?

Activity

  1. mstange commented on Aug 5, 2021

    @mstange
    Author
    • Do the contents of the fallback string have any meaning for the substitution, or are those contents completely irrelevant, except for the case where fallback actually happens? Is it only important to have "some" string that can be replaced?
  2. zbraniecki commented on Aug 5, 2021

    @zbraniecki
    Collaborator

    @stasm @gregtatum @eemeli - can you help here?

  3. mstange commented on Aug 5, 2021

    @mstange
    Author

    It would also be great to see some more complex examples involving vars. For example, can vars only take strings, or could I also do vars={{pref: <code>myprefname</code>}}, i.e. give it a react element? And if so, what would the type annotation in the comment in the ftl file look like?

  4. stasm commented on Aug 10, 2021

    @stasm
    Contributor

    All great questions, @mstange. I don't have the capacity to edit the docs, but if someone is up for doing it based on the implementation, I'll be happy to support that effort by review a PR.

  5. eemeli commented on Aug 12, 2021

    @eemeli
    Member
    • How deep does the replacement magic go? Obviously <Localized>Some string</Localized> works, and so does <Localized><div>Some string</div></Localized>, but how deep does it go?

    The replacements only apply to the immediate child, i.e. no deeper than the examples you give.

    • Which part of the react children gets replaced by the localized contents? Does it only replace raw strings, and are all "element" descendants preserved, or can it happen that an element descendant gets "localized away"?

    This depends on the value and attributes of the message that's referred to by the id prop. If it has a value, then the children of the immediate child of the <Localized> component are entirely replaced by that message value. If the message has attributes, then the attrs prop controls which of those are applied as props of the immediate child component.

    • What happens if I have multiple raw strings inside the <Localized> contents, in different descendant elements?

    If the message has a value, then they'll all be replaced. If it only has attributes and you use the attrs prop, they'll be applied to the immediate child on the <Localized> component.

    • Can <Localized> components be nested? What happens if I nest them?

    Sure, there's nothing preventing this. With the proviso that if any of the outer components refer to a message that has a non-empty value, all of its inner components will not be rendered.

    • Do the contents of the fallback string have any meaning for the substitution, or are those contents completely irrelevant, except for the case where fallback actually happens? Is it only important to have "some" string that can be replaced?

    They do not have any particular meaning in a programmatic sense, so that you're free to use a fallback message that makes sense for your context.

  6. mstange commented on Aug 12, 2021

    @mstange
    Author

    Thank you! That's very helpful.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions