Skip to content

Commit 90b96d1

Browse files
author
Tiffany Le-Nguyen
committed
chore: add testing steps
1 parent 9f1b116 commit 90b96d1

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

pages/index.js

+30-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Head from 'next/head'
22
import Header from '@components/Header'
33
import Footer from '@components/Footer'
44

5-
export default function Home() {
5+
export default function Home({locale}) {
66
return (
77
<div className="container">
88
<Head>
@@ -12,9 +12,31 @@ export default function Home() {
1212

1313
<main>
1414
<Header title="Welcome to my app!" />
15-
<p>In v3 of the next plugin, the <code>NEXT_LOCALE</code> and the `Accept-Language` header is not detected. This is fixed in v4. The workaround is manually detecting if the cookie and header exist and changing the behavior of your site in consequence.</p>
1615
<p className="description">
17-
<strong>Locale in url</strong>
16+
<strong>Locale: {locale}</strong>
17+
</p>
18+
<p>(you should see it appended to this site's url if your browser does not use the default one, <code>en</code> )</p>
19+
<p>In v3 of the next plugin, the <code>NEXT_LOCALE</code> and the `Accept-Language` header is not detected. This is fixed in v4. The workaround is manually detecting if the cookie and header exist and changing the behavior of your site in consequence.</p>
20+
<a href="https://github.com/netlify/netlify-plugin-nextjs/issues/788#issue-1050456600">See GitHub Issue for full context</a>
21+
<p>
22+
Test steps for this page:
23+
<ol>
24+
<li>
25+
Change your default browser language to french. In Chrome: language to french (Settings -> Advanced -> Language -> Add French -> Move to top)
26+
</li>
27+
<li>
28+
Refresh this page, you should see it appended with <strong>/fr</strong>, and the text on the page should change to show <strong>fr</strong>
29+
</li>
30+
<li>
31+
Open the dev tools to the console
32+
</li>
33+
<li>
34+
Enter <strong>document.cookie="NEXT_LOCALE=es"</strong>
35+
</li>
36+
<li>
37+
Refresh this page. You should see it appended with <strong>/es</strong>
38+
</li>
39+
</ol>
1840
</p>
1941
</main>
2042

@@ -25,14 +47,17 @@ export default function Home() {
2547

2648
export async function getServerSideProps(context) {
2749
const acceptLanguageHeader = context?.req?.headers['accept-language']
28-
const nextLocaleCookie = context.req.cookies?.NEXT_LOCALE
50+
const nextLocaleCookie = context.req?.cookies?.NEXT_LOCALE
51+
// Force the locale to be either the NEXT_LOCALE cookie or the Accept-Language header
2952
const locale = nextLocaleCookie
3053
? nextLocaleCookie
3154
: acceptLanguageHeader
3255
? acceptLanguageHeader
3356
: context?.req?.locale || "";
3457

3558
return {
36-
props: {},
59+
props: {
60+
locale
61+
},
3762
}
3863
}

0 commit comments

Comments
 (0)