+
+
+
+ {/* alternative language change without using Link component
+
+ */}
+ {/* alternative language change without using Link component, but this will change language only on client side
+ */}
+
+
+
+
+
+
+
+
+
+ >
+ )
+}
+
+// or getServerSideProps: GetServerSideProps = async ({ locale })
+export const getStaticProps: GetStaticProps = async ({
+ locale,
+}) => ({
+ props: {
+ ...(await serverSideTranslations(locale ?? 'en', [
+ 'common',
+ 'footer',
+ ])),
+ },
+})
+
+export default Homepage
diff --git a/examples/auto-static-optimize/pages/second-page.tsx b/examples/auto-static-optimize/pages/second-page.tsx
new file mode 100644
index 00000000..0fe5ad09
--- /dev/null
+++ b/examples/auto-static-optimize/pages/second-page.tsx
@@ -0,0 +1,51 @@
+import Link from 'next/link'
+import type {
+ GetServerSideProps,
+ InferGetServerSidePropsType,
+} from 'next'
+
+import { useTranslation } from 'next-i18next'
+import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
+
+import { Header } from '../components/Header'
+import { Footer } from '../components/Footer'
+
+type Props = {
+ // Add custom props here
+}
+
+const SecondPage = (
+ _props: InferGetServerSidePropsType
+) => {
+ const { t } = useTranslation(['common', 'second-page'])
+
+ return (
+ <>
+
+
+
+
+
+
+
+ >
+ )
+}
+
+export const getServerSideProps: GetServerSideProps = async ({
+ locale,
+}) => ({
+ props: {
+ ...(await serverSideTranslations(locale ?? 'en', [
+ 'second-page',
+ 'footer',
+ ])),
+ },
+})
+
+export default SecondPage
diff --git a/examples/auto-static-optimize/public/app.css b/examples/auto-static-optimize/public/app.css
new file mode 100644
index 00000000..90b96478
--- /dev/null
+++ b/examples/auto-static-optimize/public/app.css
@@ -0,0 +1,99 @@
+#__next {
+ font-family: 'Open Sans', sans-serif;
+ text-align: center;
+ background-image: linear-gradient(
+ to left top,
+ #ffffff,
+ #f5f5f5,
+ #eaeaea,
+ #e0e0e0,
+ #d6d6d6
+ );
+ display: flex;
+ flex-direction: column;
+ margin: 0;
+ min-height: 100vh;
+ min-width: 100vw;
+}
+
+h1,
+h2 {
+ font-family: 'Oswald', sans-serif;
+}
+
+h1 {
+ font-size: 3rem;
+ margin: 5rem 0;
+}
+h2 {
+ min-width: 18rem;
+ font-size: 2rem;
+ opacity: 0.3;
+}
+h3 {
+ font-size: 1.5rem;
+ opacity: 0.5;
+}
+
+p {
+ line-height: 1.65em;
+}
+p:nth-child(2) {
+ font-style: italic;
+ opacity: 0.65;
+ margin-top: 1rem;
+}
+
+a.github {
+ position: fixed;
+ top: 0.5rem;
+ right: 0.75rem;
+ font-size: 4rem;
+ color: #888;
+ opacity: 0.8;
+}
+a.github:hover {
+ opacity: 1;
+}
+
+button {
+ display: inline-block;
+ vertical-align: bottom;
+ outline: 0;
+ text-decoration: none;
+ cursor: pointer;
+ background-color: rgba(255, 255, 255, 0.5);
+ box-sizing: border-box;
+ font-size: 1em;
+ font-family: inherit;
+ border-radius: 3px;
+ transition: box-shadow 0.2s ease;
+ user-select: none;
+ line-height: 2.5em;
+ min-height: 40px;
+ padding: 0 0.8em;
+ border: 0;
+ color: inherit;
+ position: relative;
+ transform: translateZ(0);
+ box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
+ margin: 0.8rem;
+}
+
+button:hover,
+button:focus {
+ box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.4);
+}
+
+main {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ justify-content: center;
+ align-items: center;
+}
+footer {
+ background-color: rgba(255, 255, 255, 0.5);
+ width: 100vw;
+ padding: 3rem 0;
+}
diff --git a/examples/auto-static-optimize/public/locales/de/common.json b/examples/auto-static-optimize/public/locales/de/common.json
new file mode 100644
index 00000000..9bdc4f42
--- /dev/null
+++ b/examples/auto-static-optimize/public/locales/de/common.json
@@ -0,0 +1,26 @@
+{
+ "h1": "Ein einfaches Beispiel",
+ "change-locale": "Sprache wechseln zu \"{{changeTo}}\"",
+ "to-second-page": "Zur zweiten Seite",
+ "to-auto-static-page": "To auto static page (de)",
+ "error-with-status": "Auf dem Server ist ein Fehler ({{statusCode}}) aufgetreten",
+ "error-without-status": "Auf dem Server ist ein Fehler aufgetreten",
+ "title": "Hauptseite | next-i18next",
+ "blog": {
+ "appDir": {
+ "question": "Verwendest du das neue Next.js 13/14 mit app directory?",
+ "answer": "Dann schau dir <1>diesen Blogbeitrag1> an.",
+ "link": "https://locize.com/blog/next-app-dir-i18n/"
+ },
+ "optimized": {
+ "question": "Möchtest du einige Superkräfte entfesseln, um für alle Seiten optimierte Übersetzungen zu haben?",
+ "answer": "Dann schaue dir vielleicht <1>diesen Blogbeitrag1> an.",
+ "link": "https://locize.com/blog/next-i18next-de/"
+ },
+ "ssg": {
+ "question": "Möchtest du SSG (next export) verwenden?",
+ "answer": "Dann schaue dir vielleicht <1>diesen Blogbeitrag1> an.",
+ "link": "https://locize.com/blog/next-i18n-statisch/"
+ }
+ }
+}
diff --git a/examples/auto-static-optimize/public/locales/de/footer.json b/examples/auto-static-optimize/public/locales/de/footer.json
new file mode 100644
index 00000000..2848ba9d
--- /dev/null
+++ b/examples/auto-static-optimize/public/locales/de/footer.json
@@ -0,0 +1,4 @@
+{
+ "description": "Dies ist eine Nicht-Seitenkomponente, die einen eigenen Namespace erfordert",
+ "helpLocize": "Wenn Sie <1>locize1> einsetzen, unterstützen Sie direkt die Zukunft von <3>i18next3>."
+}
diff --git a/examples/auto-static-optimize/public/locales/de/second-page.json b/examples/auto-static-optimize/public/locales/de/second-page.json
new file mode 100644
index 00000000..73bb73f2
--- /dev/null
+++ b/examples/auto-static-optimize/public/locales/de/second-page.json
@@ -0,0 +1,5 @@
+{
+ "h1": "Eine zweite Seite, um das Routing zu demonstrieren",
+ "back-to-home": "Zurück zur Hauptseite",
+ "title": "Zweite Seite | next-i18next"
+}
diff --git a/examples/auto-static-optimize/public/locales/de/staticpage.json b/examples/auto-static-optimize/public/locales/de/staticpage.json
new file mode 100644
index 00000000..203b1c1e
--- /dev/null
+++ b/examples/auto-static-optimize/public/locales/de/staticpage.json
@@ -0,0 +1 @@
+{ "hi": "hello_de" }
diff --git a/examples/auto-static-optimize/public/locales/en/common.json b/examples/auto-static-optimize/public/locales/en/common.json
new file mode 100644
index 00000000..2ca192ef
--- /dev/null
+++ b/examples/auto-static-optimize/public/locales/en/common.json
@@ -0,0 +1,26 @@
+{
+ "h1": "A simple example",
+ "change-locale": "Change locale to \"{{changeTo}}\"",
+ "to-second-page": "To second page",
+ "to-auto-static-page": "To auto static page (en)",
+ "error-with-status": "A {{statusCode}} error occurred on server",
+ "error-without-status": "An error occurred on the server",
+ "title": "Home | next-i18next",
+ "blog": {
+ "appDir": {
+ "question": "Are you using the new Next.js 13/14 app directory?",
+ "answer": "Then check out <1>this blog post1>.",
+ "link": "https://locize.com/blog/next-app-dir-i18n/"
+ },
+ "optimized": {
+ "question": "Do you like to unleash some super powers to have all side optimized translations?",
+ "answer": "Then you may have a look at <1>this blog post1>.",
+ "link": "https://locize.com/blog/next-i18next/"
+ },
+ "ssg": {
+ "question": "Do you want to use SSG (next export)?",
+ "answer": "Then you may have a look at <1>this blog post1>.",
+ "link": "https://locize.com/blog/next-i18n-static/"
+ }
+ }
+}
diff --git a/examples/auto-static-optimize/public/locales/en/footer.json b/examples/auto-static-optimize/public/locales/en/footer.json
new file mode 100644
index 00000000..59c4bde9
--- /dev/null
+++ b/examples/auto-static-optimize/public/locales/en/footer.json
@@ -0,0 +1,4 @@
+{
+ "description": "This is a non-page component that requires its own namespace",
+ "helpLocize": "With using <1>locize1> you directly support the future of <3>i18next3>."
+}
diff --git a/examples/auto-static-optimize/public/locales/en/second-page.json b/examples/auto-static-optimize/public/locales/en/second-page.json
new file mode 100644
index 00000000..64d0decc
--- /dev/null
+++ b/examples/auto-static-optimize/public/locales/en/second-page.json
@@ -0,0 +1,5 @@
+{
+ "h1": "A second page, to demonstrate routing",
+ "back-to-home": "Back to home",
+ "title": "Second page | next-i18next"
+}
diff --git a/examples/auto-static-optimize/public/locales/en/staticpage.json b/examples/auto-static-optimize/public/locales/en/staticpage.json
new file mode 100644
index 00000000..a34a9679
--- /dev/null
+++ b/examples/auto-static-optimize/public/locales/en/staticpage.json
@@ -0,0 +1 @@
+{ "hi": "hello_en" }
diff --git a/examples/auto-static-optimize/tsconfig.json b/examples/auto-static-optimize/tsconfig.json
new file mode 100644
index 00000000..8b2f04cb
--- /dev/null
+++ b/examples/auto-static-optimize/tsconfig.json
@@ -0,0 +1,30 @@
+{
+ "$schema": "https://json.schemastore.org/tsconfig",
+ "compilerOptions": {
+ "target": "esnext",
+ "lib": ["dom", "dom.iterable", "esnext"],
+ "baseUrl": ".",
+ "allowJs": true,
+ "skipLibCheck": true,
+ "strict": true,
+ "forceConsistentCasingInFileNames": true,
+ "noEmit": true,
+ "esModuleInterop": true,
+ "module": "esnext",
+ "moduleResolution": "node",
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "jsx": "preserve",
+ "incremental": true
+ },
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ "**/*.js",
+ "**/*.jsx",
+ "**/*.cjs",
+ "**/*.mjs"
+ ],
+ "exclude": ["**/node_modules", "**/.*/"]
+}
diff --git a/examples/auto-static-optimize/vercel.json b/examples/auto-static-optimize/vercel.json
new file mode 100644
index 00000000..7ae9a3de
--- /dev/null
+++ b/examples/auto-static-optimize/vercel.json
@@ -0,0 +1,5 @@
+{
+ "github": {
+ "silent": true
+ }
+}
diff --git a/package.json b/package.json
index 776eb247..25b20ae2 100644
--- a/package.json
+++ b/package.json
@@ -47,6 +47,7 @@
"build:examples": "npm-run-all -s build:example:*",
"build:example:simple": "cd examples/simple && npm run build",
"build:example:ssg": "cd examples/ssg && npm run build",
+ "build:example:auto-static-optimize": "cd examples/auto-static-optimize && npm run build",
"typecheck": "tsc --project ./tsconfig.json --noEmit",
"typecheck:example:simple": "cd examples/simple && npm run typecheck",
"check-size": "size-limit",
@@ -59,8 +60,8 @@
"install:example:simple": "cd examples/simple && npm install",
"install:example:ssg": "cd examples/ssg && npm install",
"move-build-to-examples?": "Hack: see # @link https://github.com/i18next/next-i18next/pull/2012",
- "move-build-to-examples": "rimraf ./examples/*/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/simple/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/ssg/node_modules/next-i18next",
- "test:e2e": "start-server-and-test 'cd examples/simple && npm run start' http://127.0.0.1:3000 cy:run",
+ "move-build-to-examples": "rimraf ./examples/*/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/simple/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/ssg/node_modules/next-i18next && cpy './package.json' './*.js' './*.ts' './dist' ./examples/auto-static-optimize/node_modules/next-i18next ",
+ "test:e2e": "start-server-and-test 'cd examples/auto-static-optimize && npm run start' http://127.0.0.1:3000 cy:run",
"cy:run": "cypress run",
"example": "npm run example:simple",
"example:prod": "npm run example:simple:prod",