maybeNameTranslation method
Returns the translated name of an item by searching in order of priority: direct maps, theme PickersThemeData.maps, and global TypedLocaleDelegate translation cache.
Returns null if no translation is found in any source, or if all sources
are null.
Asserts in debug mode when a translation is missing from a non-null source, suggesting to add the item to the translation cache or use TypedLocaleDelegate for automatic translations.
Priority order:
- Direct maps parameter (highest priority).
- Theme PickersThemeData.maps.
- Global TypedLocaleDelegate translation cache (lowest priority).
Implementation
@protected
String? maybeNameTranslation(T item, BuildContext context) {
final direct = maps;
final theme = context.pickersTheme?.maps;
final global = context.maybeLocale?.maps;
if (direct == null && theme == null && global == null) return null;
String? result;
if (direct != null) {
result = nameTranslationCache(item, direct);
if (result != null) return result;
}
if (theme != null) {
result = nameTranslationCache(item, theme);
if (result != null) return result;
}
if (global != null) {
result = nameTranslationCache(item, global);
if (result != null) return result;
}
assert(
direct == null,
"The $IsoMaps passed to the `maps` parameter in the "
"$this lacks a translation for item: $item. Verify that the provided "
"${TranslationMap<T>} translations map includes a key value pair for the "
"{${item.runtimeType}(): '${item.internationalName} translation'} there."
" Consider adding `localizationsDelegates: const [TypedLocaleDelegate()]`"
" in the app to enable device locale-based auto translation maps cache.",
);
assert(
theme == null,
"The $IsoMaps passed to the `maps` parameter in "
"$PickersThemeData lacks a translation for item: $item. Verify that the "
"${TranslationMap<T>} translations map includes a key value pair for the "
"{${item.runtimeType}(): '${item.internationalName} translation'} there.",
);
assert(
global == null,
"The $TypedLocaleDelegate passed to the app's `localizationsDelegates` "
"parameter provided IsoMaps without a translation for item: $item. "
"Verify that the translation cache includes a key value pair for the "
"{${item.runtimeType}(): '${item.internationalName} translation'} there.",
);
return result;
}