File tree 8 files changed +40
-9
lines changed
examples/by-frameworks/next-intl
8 files changed +40
-9
lines changed Original file line number Diff line number Diff line change 3
3
"description" : " Eine Beschreibung" ,
4
4
"title" : " next-intl Beispiel"
5
5
},
6
+ "Metadata" : {
7
+ "title" : " Seitentitel"
8
+ },
6
9
"Test" : {
7
10
"title" : " Test"
8
11
}
Original file line number Diff line number Diff line change 3
3
"description" : " Some description" ,
4
4
"title" : " next-intl example"
5
5
},
6
+ "Metadata" : {
7
+ "title" : " Page title"
8
+ },
6
9
"Test" : {
7
10
"title" : " Test"
8
11
}
Original file line number Diff line number Diff line change
1
+ const withNextIntl = require ( 'next-intl/plugin' ) ( )
2
+
3
+ module . exports = withNextIntl ( )
Original file line number Diff line number Diff line change 10
10
},
11
11
"dependencies" : {
12
12
"next" : " ^13.4.0" ,
13
- "next-intl" : " ^2.14.1 " ,
13
+ "next-intl" : " 3.0.0-beta.17 " ,
14
14
"react" : " ^18.2.0" ,
15
15
"react-dom" : " ^18.2.0"
16
16
},
Original file line number Diff line number Diff line change @@ -21,9 +21,6 @@ export default async function LocaleLayout({
21
21
22
22
return (
23
23
< html lang = { locale } >
24
- < head >
25
- < title > next-intl</ title >
26
- </ head >
27
24
< body >
28
25
< NextIntlClientProvider locale = { locale } messages = { messages } >
29
26
{ children }
Original file line number Diff line number Diff line change 1
- 'use client'
2
1
3
2
import { useTranslations } from 'next-intl'
3
+ import { getTranslator } from 'next-intl/server'
4
+
5
+ export async function generateMetadata ( { params : { locale } } ) {
6
+ const t = await getTranslator ( locale , 'Metadata' )
7
+
8
+ return {
9
+ title : t ( 'title' ) ,
10
+ }
11
+ }
4
12
5
13
export default function IndexPage ( ) {
6
14
const t = useTranslations ( 'IndexPage' )
@@ -15,6 +23,8 @@ export default function IndexPage() {
15
23
< p > { t ( 'description' ) } </ p >
16
24
< Test1 />
17
25
< Test2 />
26
+ < Test3 />
27
+ < Test4 />
18
28
</ div >
19
29
)
20
30
}
@@ -28,3 +38,13 @@ function Test2() {
28
38
const t = useTranslations ( )
29
39
return < p > { t ( 'Test.title' ) } </ p >
30
40
}
41
+
42
+ function Test3 ( ) {
43
+ const t = useTranslations ( 'Test' )
44
+ return < p > { t ( 'title' ) } </ p >
45
+ }
46
+
47
+ function Test4 ( ) {
48
+ const t = useTranslations ( )
49
+ return < p > { t ( 'IndexPage.title' ) } </ p >
50
+ }
Original file line number Diff line number Diff line change
1
+ import { getRequestConfig } from 'next-intl/server'
2
+
3
+ export default getRequestConfig ( async ( { locale } ) => ( {
4
+ messages : ( await import ( `../messages/${ locale } .json` ) ) . default ,
5
+ } ) )
Original file line number Diff line number Diff line change @@ -79,16 +79,16 @@ class NextIntlFramework extends Framework {
79
79
const ranges : ScopeRange [ ] = [ ]
80
80
const text = document . getText ( )
81
81
82
- // Find matches of `useTranslations`, later occurences will override
83
- // previous ones (this allows for multiple components with different
82
+ // Find matches of `useTranslations` and `getTranslator`. Later occurences will
83
+ // override previous ones (this allows for multiple components with different
84
84
// namespaces in the same file).
85
- const regex = / u s e T r a n s l a t i o n s \( \s * ( [ ' " ` ] ( .* ?) [ ' " ` ] ) ? / g
85
+ const regex = / ( u s e T r a n s l a t i o n s \( \s * | g e t T r a n s l a t o r \( . * , \s * ) ( [ ' " ` ] ( .* ?) [ ' " ` ] ) ? / g
86
86
let prevGlobalScope = false
87
87
for ( const match of text . matchAll ( regex ) ) {
88
88
if ( typeof match . index !== 'number' )
89
89
continue
90
90
91
- const namespace = match [ 2 ]
91
+ const namespace = match [ 3 ]
92
92
93
93
// End previous scope
94
94
if ( prevGlobalScope )
You can’t perform that action at this time.
0 commit comments