text stringlengths 1 372 |
|---|
_NnMaterialLocalizationsDelegate. |
the value of NnMaterialLocalizations.delegate |
is an instance of the delegate, and is all |
that’s needed by an app that uses these localizations. |
the delegate class includes basic date and number format |
localizations. all of the other localizations are defined by string |
valued property getters in NnMaterialLocalizations, like this: |
<code_start> |
@override |
string get moreButtonTooltip => r'More'; |
@override |
string get aboutListTileTitleRaw => r'About $applicationname'; |
@override |
string get alertDialogLabel => r'Alert'; |
<code_end> |
these are the english translations, of course. |
to complete the job you need to change the return |
value of each getter to an appropriate nynorsk string. |
the getters return “raw” dart strings that have an r prefix, |
such as r'About $applicationname', |
because sometimes the strings contain variables with a $ prefix. |
the variables are expanded by parameterized localization methods: |
<code_start> |
@override |
string get pageRowsInfoTitleRaw => r'$firstRow–$lastRow of $rowcount'; |
@override |
string get pageRowsInfoTitleApproximateRaw => |
r'$firstRow–$lastRow of about $rowcount'; |
<code_end> |
the date patterns and symbols of the locale also need to |
be specified, which are defined in the source code as follows: |
<code_start> |
const nnLocaleDatePatterns = { |
'd': 'd.', |
'e': 'ccc', |
'eeee': 'cccc', |
'lll': 'lll', |
// ... |
} |
<code_end> |
<code_start> |
const nnDateSymbols = { |
'name': 'nn', |
'eras': <dynamic>[ |
'f.kr.', |
'e.kr.', |
], |
// ... |
} |
<code_end> |
these values need to be modified for the locale to use the correct |
date formatting. unfortunately, since the intl library doesn’t |
share the same flexibility for number formatting, |
the formatting for an existing locale must be used |
as a substitute in _NnMaterialLocalizationsDelegate: |
<code_start> |
class _NnMaterialLocalizationsDelegate |
extends LocalizationsDelegate<MaterialLocalizations> { |
const _NnMaterialLocalizationsDelegate(); |
@override |
bool isSupported(Locale locale) => locale.languageCode == 'nn'; |
@override |
Future<MaterialLocalizations> load(Locale locale) async { |
final string localeName = intl.Intl.canonicalizedLocale(locale.toString()); |
// the locale (in this case `nn`) needs to be initialized into the custom |
// date symbols and patterns setup that flutter uses. |
date_symbol_data_custom.initializeDateFormattingCustom( |
locale: localeName, |
patterns: nnLocaleDatePatterns, |
symbols: intl.DateSymbols.deserializeFromMap(nnDateSymbols), |
); |
return SynchronousFuture<MaterialLocalizations>( |
NnMaterialLocalizations( |
localeName: localeName, |
// the `intl` library's NumberFormat class is generated from CLDR data |
// (see https://github.com/dart-lang/i18n/blob/main/pkgs/intl/lib/number_symbols_data.dart). |
// unfortunately, there is no way to use a locale that isn't defined in |
// this map and the only way to work around this is to use a listed |
// locale's NumberFormat symbols. so, here we use the number formats |
// for 'en_us' instead. |
decimalFormat: intl.NumberFormat('#,##0.###', 'en_us'), |
twoDigitZeroPaddedFormat: intl.NumberFormat('00', 'en_us'), |
// DateFormat here will use the symbols and patterns provided in the |
// `date_symbol_data_custom.initializedateformattingcustom` call above. |
// however, an alternative is to simply use a supported locale's |
// DateFormat symbols, similar to NumberFormat above. |
fullYearFormat: intl.DateFormat('y', localeName), |
compactDateFormat: intl.DateFormat('yMd', localeName), |
shortDateFormat: intl.DateFormat('yMMMd', localeName), |
mediumDateFormat: intl.DateFormat('EEE, MMM d', localeName), |
longDateFormat: intl.DateFormat('EEEE, MMMM d, y', localeName), |
yearMonthFormat: intl.DateFormat('MMMM y', localeName), |
shortMonthDayFormat: intl.DateFormat('MMM d'), |
), |
); |
} |
@override |
bool shouldReload(_NnMaterialLocalizationsDelegate old) => false; |
} |
<code_end> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.