Comment

Comment by lewisl9029

One thing that I've always struggled w.r.t i18n is having to split messages up into often times less coherent chunks in order to add things like links or tooltips or styling elements in the middle of the text, which makes it more difficult to localize messages as a holistic piece independent of the source language.

For a slightly contrived example to demonstrate this, let's say you have a string like this:

"Please click here 7 times to confirm"

Where you want to make the "click here 7 times" look like a link by wrapping it in a <a> tag, or just styled differently using a styled <span>.

Using something like react-intl, which is what I've used in the past, you'd have to do something like this:

  <FormattedMessage
    id="confirm"
    defaultMessage={`Please { confirmLink } to confirm`}
    values={{
      confirmLink: 
        <a>
          <FormattedMessage 
            id="confirm-link"
            defaultMessage={`click here {clickCount, number} {clickCount, plural,
              one {time}
              other {times}
            }`}
            values={{ clickCount: 7 }}
          />
        </a>
    }}
  />
If then some language happens to require a completely different sentence structure that changes the ordering such that the "to confirm" part needs to be interleaved somewhere in the middle of the "click here 7 times" message to sound fluent, this would not be able to accommodate that.

I'm wondering how people generally deal with this, in React and elsewhere.

parent lewisl9029 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton