Skip to main content

prefer-providing-intl-examples

added in: 1.10.0

Warns when the Intl.message(), Intl.plural(), Intl.gender() or Intl.select() methods are invoked without an examples argument or have it incomplete.

To make the translator's job easier, provide examples.

Example

❌ Bad:

import 'package:intl/intl.dart';

class SomeButtonClassI18n {
static String simpleTitleWithoutExample(String source) {
// LINT
return Intl.message(
'title',
name: 'SomeButtonClassI18n_simpleTitle',
args: [source],
);
}

static String titleWithParameter(String name) {
return Intl.message(
'title $name',
name: 'SomeButtonClassI18n_titleWithParameter',
examples: const {'name': 'name', 'closeTag': 'closeTag'}, // LINT
args: [name],
);
}

static String titleWithManyParameter(String name, int value) {
return Intl.message(
'title $name, value: $value',
examples: const {'name': 'name'}, // LINT
name: 'SomeButtonClassI18n_titleWithManyParameter',
args: [name, value],
);
}
}

✅ Good:

import 'package:intl/intl.dart';

class SomeButtonClassI18n {
static String simpleTitleWithoutExample() {
return Intl.message(
'title',
name: 'SomeButtonClassI18n_simpleTitle',
);
}

static String titleWithParameter(String name) {
return Intl.message(
'title $name',
name: 'SomeButtonClassI18n_titleWithParameter',
examples: const {'name': 'name'},
args: [name],
);
}

static String titleWithManyParameter(String name, int value) {
return Intl.message(
'title $name, value: $value',
examples: const {'name': 'name', 'value': 'some'},
name: 'SomeButtonClassI18n_titleWithManyParameter',
args: [name, value],
);
}
}