feat(MessageExtractor): do not expand ICU messages before extraction
This commit is contained in:
parent
e157a065b0
commit
04a50f5832
|
@ -5,8 +5,6 @@ import {HtmlAst, HtmlElementAst} from '../html_ast';
|
|||
import {HtmlParser} from '../html_parser';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../interpolation_config';
|
||||
import {ParseError} from '../parse_util';
|
||||
|
||||
import {expandNodes} from './expander';
|
||||
import {Message, id} from './message';
|
||||
import {I18N_ATTR_PREFIX, I18nError, Part, messageFromAttribute, messageFromI18nAttribute, partition} from './shared';
|
||||
|
||||
|
@ -106,14 +104,13 @@ export class MessageExtractor {
|
|||
this._errors = [];
|
||||
this._interpolationConfig = interpolationConfig;
|
||||
|
||||
let res = this._htmlParser.parse(template, sourceUrl, true);
|
||||
if (res.errors.length > 0) {
|
||||
return new ExtractionResult([], res.errors);
|
||||
} else {
|
||||
let expanded = expandNodes(res.rootNodes);
|
||||
this._recurse(expanded.nodes);
|
||||
return new ExtractionResult(this._messages, this._errors.concat(expanded.errors));
|
||||
const res = this._htmlParser.parse(template, sourceUrl, true);
|
||||
|
||||
if (res.errors.length == 0) {
|
||||
this._recurse(res.rootNodes);
|
||||
}
|
||||
|
||||
return new ExtractionResult(this._messages, this._errors.concat(res.errors));
|
||||
}
|
||||
|
||||
private _extractMessagesFromPart(part: Part): void {
|
||||
|
|
|
@ -153,28 +153,7 @@ export function main() {
|
|||
new Message('value', 'meaning', 'desc')
|
||||
]);
|
||||
});
|
||||
|
||||
// TODO(vicb) - this should be extracted to a single message
|
||||
// see https://github.com/angular/angular/issues/9067
|
||||
xit('should extract messages from expansion forms', () => {
|
||||
let res = extractor.extract(
|
||||
`
|
||||
<div>
|
||||
{messages.length, plural,
|
||||
=0 {You have <b>no</b> messages}
|
||||
=1 {You have one message}
|
||||
other {You have messages}
|
||||
}
|
||||
</div>`,
|
||||
'someurl');
|
||||
|
||||
expect(res.messages).toEqual([
|
||||
new Message('You have <ph name="e1">no</ph> messages', 'plural_=0', null),
|
||||
new Message('You have one message', 'plural_=1', null),
|
||||
new Message('You have messages', 'plural_other', null),
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
it('should remove duplicate messages', () => {
|
||||
let res = extractor.extract(
|
||||
`
|
||||
|
@ -239,14 +218,6 @@ export function main() {
|
|||
expect(res.errors.length).toEqual(1);
|
||||
expect(res.errors[0].msg).toEqual('Unexpected character "s"');
|
||||
});
|
||||
|
||||
it('should return parse errors on unknown plural cases', () => {
|
||||
let res = extractor.extract('{n, plural, unknown {-}}', 'someUrl');
|
||||
expect(res.errors.length).toEqual(1);
|
||||
expect(res.errors[0].msg)
|
||||
.toEqual(
|
||||
'Plural cases should be "=<number>" or one of zero, one, two, few, many, other');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue