Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/[lng]/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { Header } from './components/Header'
import { Footer } from './components/Footer'
import { Link } from './components/Link'

export default async function Page() {
const { t } = await getT()
export default async function Page({ params }) {
const { lng } = await params
const { t } = await getT(lng, 'second-page')

return (
<>
Expand Down
8 changes: 2 additions & 6 deletions app/i18n/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import i18next from './i18next'
import { headerName } from './settings'
import { headers } from 'next/headers'

export async function getT(ns, options) {
const headerList = await headers()
const lng = headerList.get(headerName)
export async function getT(lng, ns, options) {
if (lng && i18next.resolvedLanguage !== lng) {
await i18next.changeLanguage(lng)
}
Expand All @@ -15,4 +11,4 @@ export async function getT(ns, options) {
t: i18next.getFixedT(lng ?? i18next.resolvedLanguage, Array.isArray(ns) ? ns[0] : ns, options?.keyPrefix),
i18n: i18next
}
}
}
4 changes: 3 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true // Recommended for the `pages` directory, default in `app`.
output: 'export',
trailingSlash: true,
reactStrictMode: true
}

module.exports = nextConfig
19 changes: 19 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charSet="utf-8"/>
<meta name="viewport" content="width=device-width"/>
<title>redirect</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next-browser-languagedetector/7.0.2/i18nextBrowserLanguageDetector.min.js"></script>
<!-- <script src="https://unpkg.com/i18next-browser-languagedetector@7.0.2/dist/umd/i18nextBrowserLanguageDetector.min.js"></script> -->
<script>
var lngDetector = new window.i18nextBrowserLanguageDetector()
var lng = lngDetector.detect()
if (lng.indexOf('it') === 0) window.location.href = '/it/'
else if (lng.indexOf('de') === 0) window.location.href = '/de/'
else window.location.href = '/en/'
</script>
</body>
</html>