-
Notifications
You must be signed in to change notification settings - Fork 27.1k
feat(i18n): add support for custom placeholder names #8010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,6 +93,47 @@ 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"); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add some unit tests for the parser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done