Skip to content

Commit

Permalink
fix(compiler): allow single quotes into named interpolations
Browse files Browse the repository at this point in the history
The regex that extract named interpolations for i18n placeholders only allowed double quotes, this PR adds the ability to use single quotes

Fixes angular#15318
  • Loading branch information
ocombe committed Mar 24, 2017
1 parent c2892da commit f97669b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/compiler/src/i18n/i18n_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ class _I18nVisitor implements html.Visitor {
}
}

const _CUSTOM_PH_EXP = /\/\/[\s\S]*i18n[\s\S]*\([\s\S]*ph[\s\S]*=[\s\S]*"([\s\S]*?)"[\s\S]*\)/g;
const _CUSTOM_PH_EXP =
/\/\/[\s\S]*i18n[\s\S]*\([\s\S]*ph[\s\S]*=[\s\S]*("|')([\s\S]*?)\1[\s\S]*\)/g;

function _extractPlaceholderName(input: string): string {
return input.split(_CUSTOM_PH_EXP)[1];
return input.split(_CUSTOM_PH_EXP)[2];
}
8 changes: 8 additions & 0 deletions packages/compiler/test/i18n/i18n_parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export function main() {
[['[before, <ph name="TEST"> exp //i18n(ph="teSt") </ph>, after]'], 'm', 'd'],
]);
});

it('should support named interpolation with single quotes', () => {
expect(
_humanizeMessages('<div i18n=\'m|d\'>before{{ exp //i18n(ph=\'teSt\') }}after</div>'))
.toEqual([
[[`[before, <ph name="TEST"> exp //i18n(ph='teSt') </ph>, after]`], 'm', 'd'],
]);
});
});

describe('blocks', () => {
Expand Down

0 comments on commit f97669b

Please sign in to comment.