prefer-intl-name
Recommends to use ${ClassName}_${ClassMemberName}
pattern for name
argument in Intl.message()
, Intl.plural()
, Intl.gender()
, Intl.select()
methods.
Using the combination of the class and method names helps keeping all generated keys unique.
Example
❌ Bad:
import 'package:intl/intl.dart';
class SomeButtonI18n {
static final String title1 = Intl.message(
'One Title',
name: 'SomeButtonI18n_titleOne', // LINT: This name is expected to be 'SomeButtonI18n_title1'.
);
final String title2 = Intl.message(
'Two Title',
name: 'titleTwo', // LINT: This name is expected to be 'SomeButtonI18n_title2'.
);
String get title3 => Intl.message(
'Three Title',
name: 'SomeButtonI18n_titleThree', // LINT: This name is expected to be 'SomeButtonI18n_title3'.
);
static String get title4 => Intl.message(
'Four Title',
name: 'SomeButtonI18n_titleFour', // LINT: This name is expected to be 'SomeButtonI18n_title4'.
);
String title5() => Intl.message(
'Five Title',
name: 'SomeButtonI18n_titleFive', // LINT: This name is expected to be 'SomeButtonI18n_title5'.
);
static String title6() {
return Intl.message(
'Six Title',
name: 'SomeButtonI18n_titleSix', // LINT: This name is expected to be 'SomeButtonI18n_title5'.
);
}
}
✅ Good:
import 'package:intl/intl.dart';
class SomeButtonCorrectI18n {
static final int number = int.parse('1');
static final String title1 = Intl.message(
'One Title',
name: 'SomeButtonCorrectI18n_title1'
);
final String title2 = Intl.message(
'Two Title',
name: 'SomeButtonCorrectI18n_title2'
);
String get title3 => Intl.message(
'Three Title',
name: 'SomeButtonCorrectI18n_title3'
);
static String get title4 => Intl.message(
'Four Title',
name: 'SomeButtonCorrectI18n_title4'
);
String get title5 => Intl.message(
'Three Title',
name: 'SomeButtonCorrectI18n_title5'
);
static String get title6 => Intl.message(
'Four Title',
name: 'SomeButtonCorrectI18n_title6'
);
}