File tree Expand file tree Collapse file tree 8 files changed +40
-9
lines changed
examples/by-frameworks/next-intl Expand file tree Collapse file tree 8 files changed +40
-9
lines changed Original file line number Diff line number Diff line change 33 "description" : " Eine Beschreibung" ,
44 "title" : " next-intl Beispiel"
55 },
6+ "Metadata" : {
7+ "title" : " Seitentitel"
8+ },
69 "Test" : {
710 "title" : " Test"
811 }
Original file line number Diff line number Diff line change 33 "description" : " Some description" ,
44 "title" : " next-intl example"
55 },
6+ "Metadata" : {
7+ "title" : " Page title"
8+ },
69 "Test" : {
710 "title" : " Test"
811 }
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 1010 },
1111 "dependencies" : {
1212 "next" : " ^13.4.0" ,
13- "next-intl" : " ^2.14.1 " ,
13+ "next-intl" : " 3.0.0-beta.17 " ,
1414 "react" : " ^18.2.0" ,
1515 "react-dom" : " ^18.2.0"
1616 },
Original file line number Diff line number Diff line change @@ -21,9 +21,6 @@ export default async function LocaleLayout({
2121
2222 return (
2323 < html lang = { locale } >
24- < head >
25- < title > next-intl</ title >
26- </ head >
2724 < body >
2825 < NextIntlClientProvider locale = { locale } messages = { messages } >
2926 { children }
Original file line number Diff line number Diff line change 1- 'use client'
21
32import { 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+ }
412
513export default function IndexPage ( ) {
614 const t = useTranslations ( 'IndexPage' )
@@ -15,6 +23,8 @@ export default function IndexPage() {
1523 < p > { t ( 'description' ) } </ p >
1624 < Test1 />
1725 < Test2 />
26+ < Test3 />
27+ < Test4 />
1828 </ div >
1929 )
2030}
@@ -28,3 +38,13 @@ function Test2() {
2838 const t = useTranslations ( )
2939 return < p > { t ( 'Test.title' ) } </ p >
3040}
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 {
7979 const ranges : ScopeRange [ ] = [ ]
8080 const text = document . getText ( )
8181
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
8484 // 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
8686 let prevGlobalScope = false
8787 for ( const match of text . matchAll ( regex ) ) {
8888 if ( typeof match . index !== 'number' )
8989 continue
9090
91- const namespace = match [ 2 ]
91+ const namespace = match [ 3 ]
9292
9393 // End previous scope
9494 if ( prevGlobalScope )
You can’t perform that action at this time.
0 commit comments