UNPKG

next-intlayer

Version:

Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.

1 lines 1.35 kB
{"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,4BAA4B;CACvC,MAAM,EAAE,MAAM,UAAU,WAAW,WAAW;CAC9C,MAAM,oBAAoB,cAClB,qBAAqB,SAAS,EACpC,CAAC,SAAS,CACX;AAiBD,QAAO;EACL,GALsBA,UAAe,EACrC,gBAZ0B,aACzB,WAA0B;AAGzB,QAFuB,gBAAgB,mBAAmB,OAAO,CAE7C;AAEpB,UAAO,QAAQ;KAEjB,CAAC,kBAAkB,CACpB,EAIA,CAAC;EAIA;EACD"}