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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated types not working with unescape "- " syntax #1740

Open
ivstiv opened this issue Mar 26, 2024 · 1 comment
Open

Generated types not working with unescape "- " syntax #1740

ivstiv opened this issue Mar 26, 2024 · 1 comment

Comments

@ivstiv
Copy link

ivstiv commented Mar 26, 2024

馃悰 Bug Report

Wrong type when using a generated interface. Doesn't work well with the dash unescape syntax {{- dontEscape}}.

When using this syntax, typescript is happy but the unescaping doesn't get applied.

  {t("app:page.test", {
    escapeOnlyThis: "bar",
    "- dontEscapeThis": "https://www.google.com",
  })}

When using this syntax, typescript is not happy but the unescaping works as intended.

  {t("app:page.test", {
    escapeOnlyThis: "bar",
    dontEscapeThis: "https://www.google.com",
  })}

Is there another way I can pass URLs in translations? I feel like I am not trying to misuse the library but if there is a better approach do let me know.

To Reproduce

  1. Define a translation like this:
"test": "foo {{escapeOnlyThis}} bar {{- dontEscapeThis}}"
  1. Generate an interface for the translations
i18next-resources-for-ts interface -i ./locales/en-gb -o ./@types/resources.d.ts
  1. Try using the translation in typescript in the following ways
const { t } = useTranslation(ALL_RESOURCES);
...
...
<Text>
  {t("app:page.test", {
    escapeOnlyThis: "bar",
    "- dontEscapeThis": "https://www.google.com",
  })}
</Text>
...
...
<Text>
  {t("app:page.test", {
    escapeOnlyThis: "bar",
    dontEscapeThis: "https://www.google.com",
  })}
</Text>

Expected behavior

I would be happy with either behaviour as long as one of them works. I am not sure which one is more consistent:

  // currently not working at runtime
  {t("app:page.test", {
    escapeOnlyThis: "bar",
    "- dontEscapeThis": "https://www.google.com",
  })}
  // currently not working at compile time, because the generated type includes "- "
  {t("app:page.test", {
    escapeOnlyThis: "bar",
    dontEscapeThis: "https://www.google.com",
  })}

Your Environment

  • "react-native": "0.72.10",
  • "i18next": "^23.8.2",
  • "react-i18next": "^14.0.5",
  • "@types/i18next": "^13.0.0",
  • "i18next-resources-for-ts": "^1.5.0",
@adrai
Copy link
Member

adrai commented Mar 29, 2024

feel free to provide a pr to address this

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

2 participants