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