i18next / i18next-icu

i18nFormat plugin to use ICU format with i18next
MIT License
81 stars 17 forks source link

i18next-icu incompatible with react-i18next <Trans> #33

Closed cellog closed 3 years ago

cellog commented 3 years ago

๐Ÿ› Bug Report

When using i18next-icu 2.0.0 with a react-i18next <Trans> component, the parsing fails, and no arguments are replaced.

This is because IntlMessageFormat 2.x did not have the ignoreTag option. Version 9.4.6 now has this, which means that when IntlMessageFormat sees a placeholder like <0></0> it expects that to exist in the options, much like the value in the reproduce case below. react-i18next and other implementations handle the placeholders above the icu parser, and so the ignoreTag option should be enabled.

To Reproduce

// Paste your code here
import { Trans } from "react-i18next/icu.macro";

function ComponentThatUsesTrans () {
  const value = "this is not replaced";
  return (
    <Trans i18nKey="some-key">
      This <b>bold tag</b> triggers an error, and as a result
      {value} is not replaced
    </Trans>
  );
}

Expected behavior

The translation should be "This <b>bold tag</b> triggers an error, and as a result this is not replaced" but is "This <b>bold tag</b> triggers an error, and as a a result {value}"

Your Environment

cellog commented 3 years ago

@jamuhl apologies to ask this again, but this is a pretty serious regression I missed in the work for 2.0.0, do you think. you might have time to look over the PR fixing it in the next few days?

cellog commented 3 years ago

(if not, it's fine, I have a stopgap, just want to know if I need to use our forked package until there is time to review, or if I can wait for 2.0.1)

tngwoerleij commented 3 years ago

Would be great to have this fixed & merged soon.

We're experiencing the same issue - I thought at first this was intended behaviour and escaped the tags, but I would be better to avoid this.

tngwoerleij commented 3 years ago

Thanks for your quick response! This fixes the issues and allows me to avoid explicitly escaping tags. I have already updated the dependency to latest 2.0.2 ๐Ÿ‘