configured localization
This commit is contained in:
14
app/i18n.ts
Normal file
14
app/i18n.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import {notFound} from 'next/navigation';
|
||||||
|
import {getRequestConfig} from 'next-intl/server';
|
||||||
|
|
||||||
|
// Can be imported from a shared config
|
||||||
|
const locales = ['en', 'hr'];
|
||||||
|
|
||||||
|
export default getRequestConfig(async ({locale}) => {
|
||||||
|
// Validate that the incoming `locale` parameter is valid
|
||||||
|
if (!locales.includes(locale as any)) notFound();
|
||||||
|
|
||||||
|
return {
|
||||||
|
messages: (await import(`../messages/${locale}.json`)).default
|
||||||
|
};
|
||||||
|
});
|
||||||
5
messages/en.json
Normal file
5
messages/en.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Index": {
|
||||||
|
"title": "Welcome!"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
messages/hr.json
Normal file
5
messages/hr.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"Index": {
|
||||||
|
"title": "Dobrodošli!"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,10 +4,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { auth } from '@/app/lib/auth'
|
import { auth } from '@/app/lib/auth'
|
||||||
|
import createIntlMiddleware from 'next-intl/middleware';
|
||||||
|
|
||||||
export default auth; // middleware will call NextAuth's `auth` method, which will in turn call) see `auth.ts`
|
const locales = ['en', 'de'];
|
||||||
|
const publicPages = ['/', '/login'];
|
||||||
|
|
||||||
|
const intlMiddleware = createIntlMiddleware({
|
||||||
|
locales,
|
||||||
|
localePrefix: 'as-needed',
|
||||||
|
defaultLocale: 'hr'
|
||||||
|
});
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
// midleware will NOT be called for paths: ['/api/auth/*', '/_next/static/*', '/_next/image*']
|
// midleware will NOT be called for paths: '/api/auth/*', '/_next/static/*', '/_next/image*', static files and public pages
|
||||||
matcher: ['/((?!api|policy|terms|_next/static|_next/image|.*\\.png$|.*\\.webm$).*)'],
|
matcher: [
|
||||||
|
'/((?!api|_next/static|_next/image|.*\\.png$|.*\\.webm$|(en|hr)/(!?policy|terms|login)).*)'
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// middleware will call NextAuth's `auth` method, which will in turn call) see `auth.ts`
|
||||||
|
export default auth((req) => {
|
||||||
|
// call the internalization middleware
|
||||||
|
return(intlMiddleware(req));
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import createNextIntlPlugin from 'next-intl/plugin';
|
||||||
|
|
||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
// Possible options:
|
// Possible options:
|
||||||
@@ -16,4 +18,9 @@ const nextConfig = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = nextConfig;
|
const withNextIntl = createNextIntlPlugin();
|
||||||
|
|
||||||
|
const nextConfigIntl = withNextIntl(nextConfig);
|
||||||
|
export default nextConfigIntl;
|
||||||
|
|
||||||
|
// module.exports = nextConfigIntl;
|
||||||
Reference in New Issue
Block a user