feat(ivy): i18n - render legacy message ids in $localize
if requested (#32937)
The `$localize` library uses a new message digest function for computing message ids. This means that translations in legacy translation files will no longer match the message ids in the code and so will not be translated. This commit adds the ability to specify the format of your legacy translation files, so that the appropriate message id can be rendered in the `$localize` tagged strings. This results in larger code size and requires that all translations are in the legacy format. Going forward the developer should migrate their translation files to use the new message id format. PR Close #32937
This commit is contained in:

committed by
atscott

parent
fc28b266cd
commit
bcbf3e4123
@ -10,15 +10,31 @@ import {newArray, utf8Encode} from '../util';
|
||||
|
||||
import * as i18n from './i18n_ast';
|
||||
|
||||
/**
|
||||
* Return the message id or compute it using the XLIFF1 digest.
|
||||
*/
|
||||
export function digest(message: i18n.Message): string {
|
||||
return message.id || sha1(serializeNodes(message.nodes).join('') + `[${message.meaning}]`);
|
||||
return message.id || computeDigest(message);
|
||||
}
|
||||
|
||||
export function decimalDigest(message: i18n.Message): string {
|
||||
if (message.id) {
|
||||
return message.id;
|
||||
}
|
||||
/**
|
||||
* Compute the message id using the XLIFF1 digest.
|
||||
*/
|
||||
export function computeDigest(message: i18n.Message): string {
|
||||
return sha1(serializeNodes(message.nodes).join('') + `[${message.meaning}]`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the message id or compute it using the XLIFF2/XMB/$localize digest.
|
||||
*/
|
||||
export function decimalDigest(message: i18n.Message): string {
|
||||
return message.id || computeDecimalDigest(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the message id using the XLIFF2/XMB/$localize digest.
|
||||
*/
|
||||
export function computeDecimalDigest(message: i18n.Message): string {
|
||||
const visitor = new _SerializerIgnoreIcuExpVisitor();
|
||||
const parts = message.nodes.map(a => a.visit(visitor, null));
|
||||
return computeMsgId(parts.join(''), message.meaning);
|
||||
|
Reference in New Issue
Block a user