LAION-AI / Open-Assistant

OpenAssistant is a chat-based assistant that understands tasks, can interact with third-party systems, and retrieve information dynamically to do so.
https://open-assistant.io
Apache License 2.0
37.05k stars 3.23k forks source link

Help needed to translate LabelLikertGroup.tsx #1416

Closed GuilleHoardings closed 1 year ago

GuilleHoardings commented 1 year ago

I've translated LabelLikertGroup.tsx with code like this:

...
import { useTranslation } from "react-i18next";
...
const getLabelInfo = (label: string): LabelInfo => {
  const { t } = useTranslation("labelling");
  switch (label) {
    case "spam":
      return {
        zeroText: t("not_spam"),
        zeroDescription: [t("not_spam.explanation")],
        oneText: t("spam"),
...

It works in my system, but when I run pre-commit, I get this error:

23:17 Error: React Hook "useTranslation" is called in function "getLabelInfo" that is neither a React function component nor a custom React Hook function. React component names must start with an uppercase letter. React Hook names must start with the word "use". react-hooks/rules-of-hooks

I kind of understand the error, but I don't know howw to fix it. Any pointers about fixing it? I've spent hours adding translations to this file and I don't want to lose this work...

notmd commented 1 year ago

You need to call useTranslation inside a component, and then pass the t function to getLabelInfo

GuilleHoardings commented 1 year ago

That works, thank you!