Code Monkey home page Code Monkey logo

Comments (5)

gustavoguichard avatar gustavoguichard commented on May 28, 2024 1

I'm glad you were able to solve it somehow.. I'm not familiar with those libraries.
Looking forward to having top level await ASAP in Node =)

from remix-forms.

gustavoguichard avatar gustavoguichard commented on May 28, 2024

We don't use remix-i18next or react-i18next and TBH I wouldn't use it unless I had a really good reason.
Translating strings require only a pure function:

declare function t(i: string): string

It is not something that should depend on a component. There'll be plenty of strings coming from the server that should not depend on being in a hook... flash messages, for instance, will need to be set on the server and they'll need translation.

What you can do is using the i18next library though. Or any other library / custom function that conforms (i: string): string IMHO

from remix-forms.

gustavoguichard avatar gustavoguichard commented on May 28, 2024

What I'm really looking after is any function that can implement:

const schema = z.object({
  name: z.string().min(3, t('forms.name')),
});

from remix-forms.

janhesters avatar janhesters commented on May 28, 2024

My workaround ended up being:

const schema = z.object({
  name: z.string().min(3, 'user-profile:name-required-and-constraints'),
});

where the component then grabs the value like this:

const Error = ({ children, ...props }: JSX.IntrinsicElements['div']) => {
  const { t } = useTranslation();

  return (
    <p className="mt-2 text-sm text-red-600" {...props}>
      {typeof children === 'string' ? t(children, children) : children}
    </p>
  );
};

@gustavoguichard thanks for the suggestion. The problem with Remix-i18next's i18next is, that it only offers i18next.getFixedT, which returns a promise and is therefore not usable for defining the schema.

from remix-forms.

founderblocks-sils avatar founderblocks-sils commented on May 28, 2024

hey, I've used this:

labels={Object.fromEntries(
Object.keys(schema.shape).map((key) => [key, t(key)])
)}

to localize the labels in case its helpful to others or worth documenting (I believe i18n is worth documenting!)

localizing errors is still on my todo list

from remix-forms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.