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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid typing of useCurrentLocale() #122

Closed
roux1max opened this issue Aug 18, 2023 · 5 comments
Closed

Invalid typing of useCurrentLocale() #122

roux1max opened this issue Aug 18, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@roux1max
Copy link

Hi!

Thanks for the work here. I was just looking at the code and noticed that the createUseCurrentLocale() function in src/app/client has a return type that does not match the returned function (the config parameter is missing). Is it intentional?

If it is, how can we provide a custom segment name?

@QuiiBz QuiiBz added the bug Something isn't working label Aug 18, 2023
@QuiiBz
Copy link
Owner

QuiiBz commented Aug 18, 2023

Thanks, I've just released 0.9.2 which fixes the type bug. You could already pass a config parameter but the type was wrong.

@QuiiBz QuiiBz closed this as completed Aug 18, 2023
@roux1max
Copy link
Author

Awesome! Thanks!

In the same spirit, getStaticParams does not take a config param to change the segment name which means that if you use a segment name that is different than "locale", it won't work.

@QuiiBz
Copy link
Owner

QuiiBz commented Aug 18, 2023

getStaticParams doesn't need the segment name, as it uses directly the keys of the locales object from createI18nServer:

export function createGetStaticParams<Locales extends ImportedLocales>(locales: Locales) {

@roux1max
Copy link
Author

It does, the key returned by each object in the array is 'locale', which will match the path segment as per NextJs documentation.

In order for createGetStaticParams to work, it would need to be changed to something like this:

export function createGetStaticParams<Locales extends ImportedLocales>(locales: Locales) {
  return function getStaticParams(config?: I18nCurrentLocaleConfig) {
    return Object.keys(locales).map(locale => ({
      [config?.segmentName ?? DEFAULT_SEGMENT_NAME]: locale,
    }));
  };
}

@QuiiBz
Copy link
Owner

QuiiBz commented Aug 19, 2023

Oh I understand what you mean now, sorry. I'll make another fix for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants