prefer-providing-intl-examples
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: Missing the 'examples' argument. Try providing it.
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: Redundant examples: closeTag. Try removing them.
args: [name],
);
}
static String titleWithManyParameter(String name, int value) {
return Intl.message(
'title $name, value: $value',
examples: const {'name': 'name'}, // LINT: Missing examples for: value. Try adding them.
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],
);
}
}