Skip to content

Commit

Permalink
fix(i18n): do not warn with interpolation in i18n element
Browse files Browse the repository at this point in the history
Fix #442
  • Loading branch information
mgechev committed Jan 9, 2018
1 parent a150939 commit 4c1c8d4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/i18nRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class I18NTextVisitor extends BasicTemplateAstVisitor implements ConfigurableVis
if (!this.visited.has(text)) {
this.visited.add(text);
const val = text.value;
if (val instanceof ast.ASTWithSource && val.ast instanceof ast.Interpolation) {
if (val instanceof ast.ASTWithSource && val.ast instanceof ast.Interpolation && !this.hasI18n) {
const textNonEmpty = val.ast.strings.some(s => /\w+/.test(s));
if (textNonEmpty) {
const span = text.sourceSpan;
Expand Down
44 changes: 29 additions & 15 deletions test/i18nRule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getAst = (code: string, file = 'file.ts') => {
describe('i18n', () => {
describe('check-id', () => {
it('should work with proper id', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n="test@@foo">Text</div>
Expand All @@ -25,8 +25,22 @@ describe('i18n', () => {
assertSuccess('i18n', source, ['check-id']);
});

it('should work with proper i18n attribute', () => {
const source = `
@Component({
template: \`
<div i18n="@@minlength">
Use at least {{ minLength }} characters
</div>
\`
})
class Bar {}
`;
assertSuccess('i18n', source, ['check-text']);
});

it('should work with proper id', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n="meaning|description@@foo">Text</div>
Expand All @@ -38,7 +52,7 @@ describe('i18n', () => {
});

it('should work with proper id', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n="@@foo">Text</div>
Expand All @@ -50,7 +64,7 @@ describe('i18n', () => {
});

it('should fail with missing id string', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n="foo@@">Text</div>
Expand All @@ -68,7 +82,7 @@ describe('i18n', () => {
});

it('should fail with missing id', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n="foo">Text</div>
Expand All @@ -86,7 +100,7 @@ describe('i18n', () => {
});

it('should fail with missing id', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n>Text</div>
Expand All @@ -106,7 +120,7 @@ describe('i18n', () => {

describe('check-text', () => {
it('should work with i18n attribute', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n>Text</div>
Expand All @@ -118,7 +132,7 @@ describe('i18n', () => {
});

it('should work without i18n attribute & interpolation', () => {
let source = `
const source = `
@Component({
template: \`
<div>{{text}}</div>
Expand All @@ -130,7 +144,7 @@ describe('i18n', () => {
});

it('should work with multiple valid elements', () => {
let source = `
const source = `
@Component({
template: \`
<div>{{text}}</div>
Expand All @@ -146,7 +160,7 @@ describe('i18n', () => {
});

it('should fail with missing id string', () => {
let source = `
const source = `
@Component({
template: \`
<div>Text</div>
Expand All @@ -164,7 +178,7 @@ describe('i18n', () => {
});

it('should fail with missing id string in nested elements', () => {
let source = `
const source = `
@Component({
template: \`
<div>
Expand All @@ -185,7 +199,7 @@ describe('i18n', () => {
});

it('should fail with text outside element with i18n attribute', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n>Text</div>
Expand Down Expand Up @@ -213,7 +227,7 @@ describe('i18n', () => {
});

it('should fail with missing id string', () => {
let source = `
const source = `
@Component({
template: \`
<div>Text {{ foo }}</div>
Expand All @@ -231,7 +245,7 @@ describe('i18n', () => {
});

it('should fail with missing id string', () => {
let source = `
const source = `
@Component({
template: \`
<div>{{ foo }} text</div>
Expand All @@ -249,7 +263,7 @@ describe('i18n', () => {
});

it('should fail with text outside element with i18n attribute', () => {
let source = `
const source = `
@Component({
template: \`
<div i18n>Text</div>
Expand Down

0 comments on commit 4c1c8d4

Please sign in to comment.