This is often requested feature — t macro should accept custom id and/or comment. Using defineMessage in combination with i18n._ is unnecessary verbose.
Proposal
TLDR: Same api as defineMessage, but the output will be wrapped in i18n._ as t and other macros does:
t({
id: 'msgId,
message: 'text'
})
// ↓ ↓ ↓ ↓ ↓ ↓
i18n._(/*i18n*/{ id: "msgId", values: { name }, message: 'text' })
t({
id: 'msgId,
message: 'text',
comment: 'description for translators'
})
// ↓ ↓ ↓ ↓ ↓ ↓
i18n._(/*i18n*/{ id: "msgId", values: { name }, message: 'text', comment: 'description for translators' })
t({
id: 'msgId,
message: plural(value, { one: '...', other: '...' })
})
// ↓ ↓ ↓ ↓ ↓ ↓
i18n._(/*i18n*/{ id: "msgId", values: { name }, message: '{value, plural, one {...} other {...}' })
// Important! This should still work:
t`Hello World`
i18n._(/*i18n*/{ id: 'Hello World')
This should be fairly easy, because all logic for parsing messge descriptors is already inside defineMessage macro. It just needs an extra if in the right location, so the t macro can be used either as a template literal tag or a function.
Tasks
Related issues: #797 #701
This is often requested feature —
tmacro should accept customidand/orcomment. UsingdefineMessagein combination withi18n._is unnecessary verbose.Proposal
TLDR: Same api as
defineMessage, but the output will be wrapped ini18n._astand other macros does:This should be fairly easy, because all logic for parsing messge descriptors is already inside
defineMessagemacro. It just needs an extraifin the right location, so thetmacro can be used either as a template literal tag or a function.Tasks
tmacro inmacroJs.tsto also accept message descriptor, the same way howdefineMessagedoesjs-t.tsto cover new usecasestmacro docsRelated issues: #797 #701