@@ -17,7 +17,7 @@ import {
17
17
VNodeArrayChildren
18
18
} from 'vue'
19
19
import { WritableComputedRef , ComputedRef } from '@vue/reactivity'
20
- import { Path , parse as parsePath } from './path'
20
+ import { Path , parse as parsePath , resolveValue } from './path'
21
21
import {
22
22
DateTimeFormats as DateTimeFormatsType ,
23
23
NumberFormats as NumberFormatsType ,
@@ -34,6 +34,7 @@ import {
34
34
} from './message/runtime'
35
35
import {
36
36
Locale ,
37
+ LocaleMessageValue ,
37
38
LocaleMessages ,
38
39
createRuntimeContext ,
39
40
RuntimeContext ,
@@ -195,6 +196,7 @@ export interface Composer<
195
196
n ( value : number , key : string , locale : Locale ) : string
196
197
n ( value : number , options : NumberOptions ) : string
197
198
n ( ...args : unknown [ ] ) : string // for internal
199
+ tm ( key : Path ) : LocaleMessageValue < Message > | { }
198
200
getLocaleMessage ( locale : Locale ) : LocaleMessageDictionary < Message >
199
201
setLocaleMessage (
200
202
locale : Locale ,
@@ -696,6 +698,18 @@ export function createComposer<
696
698
)
697
699
}
698
700
701
+ // tm
702
+ function tm ( key : Path ) : LocaleMessageValue < Message > | { } {
703
+ const messages = _messages . value [ _locale . value ] || { }
704
+ const target = resolveValue ( messages , key )
705
+ // prettier-ignore
706
+ return target != null
707
+ ? target as LocaleMessageValue < Message >
708
+ : __root
709
+ ? __root . tm ( key ) as LocaleMessageValue < Message > || { }
710
+ : { }
711
+ }
712
+
699
713
// getLocaleMessage
700
714
function getLocaleMessage ( locale : Locale ) : LocaleMessageDictionary < Message > {
701
715
return ( _messages . value [ locale ] || { } ) as LocaleMessageDictionary < Message >
@@ -869,6 +883,7 @@ export function createComposer<
869
883
t,
870
884
d,
871
885
n,
886
+ tm,
872
887
getLocaleMessage,
873
888
setLocaleMessage,
874
889
mergeLocaleMessage,
0 commit comments