Commit 184a518 1 parent cc73ffd commit 184a518 Copy full SHA for 184a518
File tree 3 files changed +14
-2
lines changed
examples/by-frameworks/next-intl/src/app/[locale]
3 files changed +14
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { getTranslations } from 'next-intl/server'
2
+
3
+ export default async function GetTranslationsTest3 ( ) {
4
+ const t = await getTranslations ( {
5
+ locale : 'en' ,
6
+ namespace : 'IndexPage' ,
7
+ } )
8
+ return < p > { t ( 'title' ) } </ p >
9
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import UseTranslationsTest1 from './UseTranslationsTest1'
5
5
import UseTranslationsTest2 from './UseTranslationsTest2'
6
6
import GetTranslationsTest1 from './GetTranslationsTest1'
7
7
import GetTranslationsTest2 from './GetTranslationsTest2'
8
+ import GetTranslationsTest3 from './GetTranslationsTest3'
8
9
9
10
export async function generateMetadata ( { params : { locale } } ) {
10
11
const t = await getTranslations ( { locale, namespace : 'Metadata' } )
@@ -30,6 +31,7 @@ export default function IndexPage() {
30
31
< UseTranslationsTest2 />
31
32
< GetTranslationsTest1 />
32
33
< GetTranslationsTest2 />
34
+ < GetTranslationsTest3 />
33
35
< InlineTest1 />
34
36
< InlineTest2 />
35
37
< InlineTest3 />
Original file line number Diff line number Diff line change @@ -84,8 +84,9 @@ class NextIntlFramework extends Framework {
84
84
85
85
// Find matches of `useTranslations` and `getTranslations`. Later occurences will
86
86
// override previous ones (this allows for multiple components with different
87
- // namespaces in the same file).
88
- 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 i o n s \( \s * ) ( [ ' " ` ] ( .* ?) [ ' " ` ] ) ? / g
87
+ // namespaces in the same file). Note that `getTranslations` can either be called
88
+ // with a single string argument or an object with a `namespace` key.
89
+ 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 i o n s \( \s * | n a m e s p a c e : \s + ) ( [ ' " ` ] ( .* ?) [ ' " ` ] ) ? / g
89
90
let prevGlobalScope = false
90
91
for ( const match of text . matchAll ( regex ) ) {
91
92
if ( typeof match . index !== 'number' )
You can’t perform that action at this time.
0 commit comments