Revert "feat(i18n): add support for custom placeholder names"
This reverts commit 2abb414cfb.
This commit is contained in:
@@ -103,8 +103,6 @@ export function main() {
|
||||
|
||||
it('should parse grouped expressions', () => { checkAction("(1 + 2) * 3", "1 + 2 * 3"); });
|
||||
|
||||
it('should ignore comments in expressions', () => { checkAction('a //comment', 'a'); });
|
||||
|
||||
it('should parse an empty string', () => { checkAction(''); });
|
||||
|
||||
describe("literals", () => {
|
||||
@@ -271,8 +269,6 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should parse conditional expression', () => { checkBinding('a < b ? a : b'); });
|
||||
|
||||
it('should ignore comments in bindings', () => { checkBinding('a //comment', 'a'); });
|
||||
});
|
||||
|
||||
describe('parseTemplateBindings', () => {
|
||||
@@ -428,9 +424,6 @@ export function main() {
|
||||
it('should parse expression with newline characters', () => {
|
||||
checkInterpolation(`{{ 'foo' +\n 'bar' +\r 'baz' }}`, `{{ "foo" + "bar" + "baz" }}`);
|
||||
});
|
||||
|
||||
it('should ignore comments in interpolation expressions',
|
||||
() => { checkInterpolation('{{a //comment}}', '{{ a }}'); });
|
||||
});
|
||||
|
||||
describe("parseSimpleBinding", () => {
|
||||
|
||||
@@ -76,36 +76,6 @@ export function main() {
|
||||
.toEqual([[HtmlElementAst, 'div', 0], [HtmlAttrAst, 'value', '{{b}} or {{a}}']]);
|
||||
});
|
||||
|
||||
it('should handle interpolation with custom placeholder names', () => {
|
||||
let translations: {[key: string]: string} = {};
|
||||
translations[id(new Message('<ph name="FIRST"/> and <ph name="SECOND"/>', null, null))] =
|
||||
'<ph name="SECOND"/> or <ph name="FIRST"/>';
|
||||
|
||||
expect(
|
||||
humanizeDom(parse(
|
||||
`<div value='{{a //i18n(ph="FIRST")}} and {{b //i18n(ph="SECOND")}}' i18n-value></div>`,
|
||||
translations)))
|
||||
.toEqual([
|
||||
[HtmlElementAst, 'div', 0],
|
||||
[HtmlAttrAst, 'value', '{{b //i18n(ph="SECOND")}} or {{a //i18n(ph="FIRST")}}']
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle interpolation with duplicate placeholder names', () => {
|
||||
let translations: {[key: string]: string} = {};
|
||||
translations[id(new Message('<ph name="FIRST"/> and <ph name="FIRST_1"/>', null, null))] =
|
||||
'<ph name="FIRST_1"/> or <ph name="FIRST"/>';
|
||||
|
||||
expect(
|
||||
humanizeDom(parse(
|
||||
`<div value='{{a //i18n(ph="FIRST")}} and {{b //i18n(ph="FIRST")}}' i18n-value></div>`,
|
||||
translations)))
|
||||
.toEqual([
|
||||
[HtmlElementAst, 'div', 0],
|
||||
[HtmlAttrAst, 'value', '{{b //i18n(ph="FIRST")}} or {{a //i18n(ph="FIRST")}}']
|
||||
]);
|
||||
});
|
||||
|
||||
it("should handle nested html", () => {
|
||||
let translations: {[key: string]: string} = {};
|
||||
translations[id(new Message('<ph name="e0">a</ph><ph name="e2">b</ph>', null, null))] =
|
||||
@@ -228,7 +198,7 @@ export function main() {
|
||||
|
||||
expect(
|
||||
humanizeErrors(parse("<div value='hi {{a}}' i18n-value></div>", translations).errors))
|
||||
.toEqual(["Invalid interpolation name '99'"]);
|
||||
.toEqual(["Invalid interpolation index '99'"]);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -237,4 +207,4 @@ export function main() {
|
||||
|
||||
function humanizeErrors(errors: ParseError[]): string[] {
|
||||
return errors.map(error => error.msg);
|
||||
}
|
||||
}
|
||||
@@ -93,47 +93,6 @@ export function main() {
|
||||
.toEqual([new Message('Hi <ph name="0"/> and <ph name="1"/>', null, null)]);
|
||||
});
|
||||
|
||||
it('should replace interpolation with named placeholders if provided (text nodes)', () => {
|
||||
let res = extractor.extract(`
|
||||
<div i18n>Hi {{one //i18n(ph="FIRST")}} and {{two //i18n(ph="SECOND")}}</div>`,
|
||||
'someurl');
|
||||
expect(res.messages)
|
||||
.toEqual([
|
||||
new Message('<ph name="t0">Hi <ph name="FIRST"/> and <ph name="SECOND"/></ph>', null,
|
||||
null)
|
||||
]);
|
||||
});
|
||||
|
||||
it('should replace interpolation with named placeholders if provided (attributes)', () => {
|
||||
let res = extractor.extract(`
|
||||
<div title='Hi {{one //i18n(ph="FIRST")}} and {{two //i18n(ph="SECOND")}}'
|
||||
i18n-title></div>`,
|
||||
'someurl');
|
||||
expect(res.messages)
|
||||
.toEqual([new Message('Hi <ph name="FIRST"/> and <ph name="SECOND"/>', null, null)]);
|
||||
});
|
||||
|
||||
it('should match named placeholders with extra spacing', () => {
|
||||
let res = extractor.extract(`
|
||||
<div title='Hi {{one // i18n ( ph = "FIRST" )}} and {{two // i18n ( ph = "SECOND" )}}'
|
||||
i18n-title></div>`,
|
||||
'someurl');
|
||||
expect(res.messages)
|
||||
.toEqual([new Message('Hi <ph name="FIRST"/> and <ph name="SECOND"/>', null, null)]);
|
||||
});
|
||||
|
||||
it('should suffix duplicate placeholder names with numbers', () => {
|
||||
let res = extractor.extract(`
|
||||
<div title='Hi {{one //i18n(ph="FIRST")}} and {{two //i18n(ph="FIRST")}} and {{three //i18n(ph="FIRST")}}'
|
||||
i18n-title></div>`,
|
||||
'someurl');
|
||||
expect(res.messages)
|
||||
.toEqual([
|
||||
new Message('Hi <ph name="FIRST"/> and <ph name="FIRST_1"/> and <ph name="FIRST_2"/>',
|
||||
null, null)
|
||||
]);
|
||||
});
|
||||
|
||||
it("should handle html content", () => {
|
||||
let res = extractor.extract(
|
||||
'<div i18n><div attr="value">zero<div>one</div></div><div>two</div></div>', "someurl");
|
||||
|
||||
Reference in New Issue
Block a user