You can create your own tagged templates function to handle transformation of the trans-unit id:
const transUnitId = '@@Messages.Greeting';
const name = 'Joe';
const message = $localizeId`${transUnitId}:TRANSUNITID:Hi ${name}:NAME:, translated with run-time created trans-unit id.`;
// Original
// message = Hi Joe, translated with run-time created trans-unit id.
// German
// message = Hallo Joe, übersetzt mit einer zur Laufzeit erstellten Trans-Unit-Id.
export function $localizeId(messageParts: TemplateStringsArray, ...expressions: any[]): string {
// Create writeable copies
const messagePartsCopy: any = [...messageParts];
const messagePartsRawCopy = [...messageParts.raw];
// Strip trans-unit-id element
const prefix = messagePartsCopy.shift();
const prefixRaw = messagePartsRawCopy.shift();
const transUnitId = expressions.shift();
// Re-add prefix and replace :TRANSUNITID: with transUnitId.
messagePartsCopy[0] = prefix + messagePartsCopy[0].replace(':TRANSUNITID:', `:@@${transUnitId}:`);
messagePartsRawCopy[0] = prefixRaw + messagePartsRawCopy[0].replace(':TRANSUNITID:', `:${transUnitId}:`);
// Create messageParts object
Object.defineProperty(messagePartsCopy, 'raw', {value: messagePartsRawCopy});
// Call original localize function
return $localize(messagePartsCopy as TemplateStringsArray, ...expressions);
}