findKeysForText method
Implementation
List<String> findKeysForText(String text, String locale) {
final needle = text.trim();
if (needle.isEmpty) return const [];
final exact = <String>[];
final fuzzy = <String>[];
final matched = <String>{};
void consider(Map<String, dynamic> source) {
final flat = flattenStrings(source);
for (final entry in flat.entries) {
if (matched.contains(entry.key)) continue;
final value = entry.value.trim();
if (value == needle) {
exact.add(entry.key);
matched.add(entry.key);
continue;
}
if (_placeholderPattern.hasMatch(entry.value) &&
_placeholderMatches(entry.value, needle)) {
fuzzy.add(entry.key);
matched.add(entry.key);
}
}
}
consider(merged(locale));
consider(_bundled[locale] ?? const {});
for (final other in locales) {
if (other == locale) continue;
consider(merged(other));
consider(_bundled[other] ?? const {});
}
return [...exact, ...fuzzy];
}