refatcor(digestMessage): takes a `i18n.Message`
This commit is contained in:
parent
4028fcaa51
commit
8c9c0986e9
|
@ -338,7 +338,7 @@ class _Visitor implements html.Visitor {
|
|||
// translate the given message given the `TranslationBundle`
|
||||
private _translateMessage(el: html.Node, message: i18n.Message): html.Node[] {
|
||||
if (message && this._mode === _VisitorMode.Merge) {
|
||||
const id = msgBundle.digestMessage(message.nodes, message.meaning);
|
||||
const id = msgBundle.digestMessage(message);
|
||||
const nodes = this._translations.get(id);
|
||||
|
||||
if (nodes) {
|
||||
|
@ -374,7 +374,7 @@ class _Visitor implements html.Visitor {
|
|||
if (i18nAttributeMeanings.hasOwnProperty(attr.name)) {
|
||||
const meaning = i18nAttributeMeanings[attr.name];
|
||||
const message: i18n.Message = this._createI18nMessage([attr], meaning, '');
|
||||
const id = msgBundle.digestMessage(message.nodes, message.meaning);
|
||||
const id = msgBundle.digestMessage(message);
|
||||
const nodes = this._translations.get(id);
|
||||
if (!nodes) {
|
||||
this._reportError(
|
||||
|
|
|
@ -39,16 +39,15 @@ export class MessageBundle {
|
|||
return i18nParserResult.errors;
|
||||
}
|
||||
|
||||
i18nParserResult.messages.forEach((message) => {
|
||||
this._messageMap[digestMessage(message.nodes, message.meaning)] = message;
|
||||
});
|
||||
i18nParserResult.messages.forEach(
|
||||
(message) => { this._messageMap[digestMessage(message)] = message; });
|
||||
}
|
||||
|
||||
write(serializer: Serializer): string { return serializer.write(this._messageMap); }
|
||||
}
|
||||
|
||||
export function digestMessage(nodes: i18n.Node[], meaning: string): string {
|
||||
return strHash(serializeNodes(nodes).join('') + `[${meaning}]`);
|
||||
export function digestMessage(message: i18n.Message): string {
|
||||
return strHash(serializeNodes(message.nodes).join('') + `[${message.meaning}]`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -373,9 +373,9 @@ function fakeTranslate(
|
|||
|
||||
const i18nMsgMap: {[id: string]: html.Node[]} = {};
|
||||
|
||||
messages.forEach(msg => {
|
||||
const id = digestMessage(msg.nodes, msg.meaning);
|
||||
const text = serializeI18nNodes(msg.nodes).join('');
|
||||
messages.forEach(message => {
|
||||
const id = digestMessage(message);
|
||||
const text = serializeI18nNodes(message.nodes).join('');
|
||||
i18nMsgMap[id] = [new html.Text(`**${text}**`, null)];
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue