Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,8 @@ export function createComposer<
const interpolate = (val: unknown): MessageType<VNode> => val as VNode
const processor = {
normalize,
interpolate
interpolate,
type: 'vnode'
} as MessageProcessor<VNode>

// __transrateVNode, using for `i18n-t` component
Expand Down
8 changes: 8 additions & 0 deletions src/message/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const enum HelperNameMap {
PLURAL = 'plural',
LINKED = 'linked',
MESSAGE = 'message',
TYPE = 'type',
INTERPOLATE = 'interpolate',
NORMALIZE = 'normalize'
}
Expand All @@ -94,6 +95,7 @@ export interface MessageContext<T = string> {
plural(messages: T[]): T
linked(key: Path, modifier?: string): MessageType<T>
message(key: Path): MessageFunction<T>
type: string
interpolate: MessageInterpolate<T>
normalize: MessageNormalize<T>
}
Expand Down Expand Up @@ -202,6 +204,11 @@ export function createMessageContext<T = string, N = {}>(
? options.processor.interpolate
: ((DEFAULT_INTERPOLATE as unknown) as MessageInterpolate<T>)

const type =
isPlainObject(options.processor) && isString(options.processor.type)
? options.processor.type
: DEFAULT_MESSAGE_DATA_TYPE

const ctx = {
[HelperNameMap.LIST]: list,
[HelperNameMap.NAMED]: named,
Expand All @@ -212,6 +219,7 @@ export function createMessageContext<T = string, N = {}>(
return isString(modifier) ? _modifier(modifier)(msg as T) : msg
},
[HelperNameMap.MESSAGE]: message,
[HelperNameMap.TYPE]: type,
[HelperNameMap.INTERPOLATE]: interpolate,
[HelperNameMap.NORMALIZE]: normalize
}
Expand Down
4 changes: 3 additions & 1 deletion test/message/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,11 @@ describe('custom process', () => {
const ctx = createMessageContext<string | MockVNode>({
processor: {
normalize,
interpolate
interpolate,
type: 'mock'
}
})
expect(ctx.type).toEqual('mock')
expect(msg(ctx)).toMatchSnapshot()
})

Expand Down