feat(ExtractorMerger): ignore implicit tags in translatable sections

This commit is contained in:
Victor Berchet
2016-08-05 14:45:47 -07:00
committed by Alex Rickabaugh
parent 1b04d70626
commit dd68ae3ef1
2 changed files with 34 additions and 16 deletions

View File

@ -54,6 +54,12 @@ export function main() {
it('should not create a message for empty elements',
() => { expect(extract('<div i18n="m|d"></div>')).toEqual([]); });
it('should ignore implicit elements in translatable elements', () => {
expect(extract('<div i18n="m|d"><p></p></div>', ['p'])).toEqual([
[['<ph tag name="START_PARAGRAPH"></ph name="CLOSE_PARAGRAPH">'], 'm', 'd']
]);
});
});
describe('blocks', () => {
@ -68,6 +74,13 @@ export function main() {
]);
});
it('should ignore implicit elements in blocks', () => {
expect(extract('<!-- i18n:m|d --><p></p><!-- /i18n -->', ['p'])).toEqual([
[['<ph tag name="START_PARAGRAPH"></ph name="CLOSE_PARAGRAPH">'], 'm', 'd']
]);
});
it('should extract siblings', () => {
expect(
extract(
@ -141,12 +154,30 @@ export function main() {
it('should not extract ICU messages outside of i18n sections',
() => { expect(extract('{count, plural, =0 {text}}')).toEqual([]); });
it('should not extract nested ICU messages', () => {
it('should ignore nested ICU messages', () => {
expect(extract('<div i18n="m|d">{count, plural, =0 { {sex, gender, =m {m}} }}</div>'))
.toEqual([
[['{count, plural, =0 {[{sex, gender, =m {[m]}}, ]}}'], 'm', 'd'],
]);
});
it('should ignore implicit elements in non translatable ICU messages', () => {
expect(
extract(
'<div i18n="m|d">{count, plural, =0 { {sex, gender, =m {<p>ignore</p>}} }}</div>',
['p']))
.toEqual([[
[
'{count, plural, =0 {[{sex, gender, =m {[<ph tag name="START_PARAGRAPH">ignore</ph name="CLOSE_PARAGRAPH">]}}, ]}}'
],
'm', 'd'
]]);
});
it('should ignore implicit elements in non translatable ICU messages', () => {
expect(extract('{count, plural, =0 { {sex, gender, =m {<p>ignore</p>}} }}', ['p']))
.toEqual([]);
});
});
describe('attributes', () => {
@ -297,20 +328,6 @@ export function main() {
]);
});
});
describe('implicit elements', () => {
it('should report implicit element in translatable element', () => {
expect(extractErrors(`<p i18n><b></b></p>`, ['b'])).toEqual([
['Could not mark an element as translatable inside a translatable section', '<b>'],
]);
});
it('should report implicit element in translatable blocks', () => {
expect(extractErrors(`<!-- i18n --><b></b><!-- /i18n -->`, ['b'])).toEqual([
['Could not mark an element as translatable inside a translatable section', '<b>'],
]);
});
});
});
});