amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.29k stars 211 forks source link

☂️ Umbrella: List of potential features / changes for a major version #779

Open amannn opened 7 months ago

amannn commented 7 months ago

The big goal for the next major release is to get everything out of the way that a) makes the setup harder than necessary and b) could slow down feature development for the foreseeable future.

Features that we can already introduce in 2.x in a backwards-compatible way:

This is a list of ideas for API changes that we could potentially introduce in a major version:

No decision has been made on these so far, but if you have feedback about these points, please leave it here!

amannn commented 7 months ago

Adding the prefix for getPathname was also discussed in https://github.com/amannn/next-intl/discussions/785#discussioncomment-8159571.

vricop commented 4 months ago

Return typed messages from useMessages would be really nice.

Does anyone know a workaround for this?

vricop commented 4 months ago

Return typed messages from useMessages would be really nice.

Does anyone know a workaround for this?

I find out how to properly type safe the useMessages hook temporarily.

We can overload the function in our ./global.d.ts types like this:

import en from 'messages/en.json'

export type Messages = typeof en

declare module 'next-intl' {
  interface IntlMessages extends Messages {}

  function useMessages(): IntlMessages;
}

image

vricop commented 4 months ago

Return typed messages from useMessages would be really nice. Does anyone know a workaround for this?

I find out how to properly type safe the useMessages hook temporarily.

We can overload the function in our ./global.d.ts types like this:

import en from 'messages/en.json'

export type Messages = typeof en

declare module 'next-intl' {
  interface IntlMessages extends Messages {}

  function useMessages(): IntlMessages;
}

image

⚠️🚨 DON'T DO THIS. I FIND OUT IT BREAKS t() TYPE SAFETY ⚠️🚨

After trying many things I ended using type assertion with as:

 const t = useTranslations()
 const message = useMessages() as unknown as Messages

Not ideal, but at least there's a workaround.