added tons of features
This commit is contained in:
42
i18n/request.ts
Normal file
42
i18n/request.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import {Formats, hasLocale} from 'next-intl'
|
||||
import {getRequestConfig} from 'next-intl/server'
|
||||
|
||||
import {routing} from './routing'
|
||||
|
||||
export const formats = {
|
||||
dateTime: {
|
||||
short: {
|
||||
day: 'numeric',
|
||||
month: 'short',
|
||||
year: 'numeric'
|
||||
}
|
||||
},
|
||||
number: {
|
||||
precise: {
|
||||
maximumFractionDigits: 2
|
||||
}
|
||||
},
|
||||
list: {
|
||||
enumeration: {
|
||||
style: 'long',
|
||||
type: 'conjunction'
|
||||
}
|
||||
}
|
||||
} satisfies Formats
|
||||
|
||||
export default getRequestConfig(async ({requestLocale}) => {
|
||||
// Typically corresponds to the `[locale]` segment
|
||||
const requested = await requestLocale
|
||||
const locale = hasLocale(routing.locales, requested)
|
||||
? requested
|
||||
: routing.defaultLocale
|
||||
|
||||
/**
|
||||
* https://dev.to/hpouyanmehr/split-your-translations-in-next-intl-in-a-nice-way-4jof
|
||||
* Split your translations in `next-intl` in a nice way!
|
||||
*/
|
||||
return {
|
||||
locale,
|
||||
messages: (await import(`../messages/${locale}.json`)).default
|
||||
}
|
||||
})
|
||||
23
i18n/routing.ts
Normal file
23
i18n/routing.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import {createNavigation} from 'next-intl/navigation'
|
||||
import {defineRouting} from 'next-intl/routing'
|
||||
|
||||
import {i18n} from '@/i18n-config'
|
||||
|
||||
export const locales = i18n.locales.map(locale => locale.code)
|
||||
|
||||
export const routing = defineRouting({
|
||||
locales,
|
||||
defaultLocale: i18n.defaultLocale,
|
||||
localePrefix: 'as-needed',
|
||||
localeCookie: {
|
||||
// Expire in one year
|
||||
maxAge: 60 * 60 * 24 * 365
|
||||
}
|
||||
/* pathnames: {
|
||||
// If all locales use the same pathname, a single
|
||||
// external path can be used for all locales
|
||||
} */
|
||||
})
|
||||
|
||||
export const {Link, redirect, usePathname, useRouter, getPathname} =
|
||||
createNavigation(routing)
|
||||
Reference in New Issue
Block a user