Add a release codegen mode where missing translations throw instead of returning the original text.
Also includes a regex fix that was causing us to miss the edge case of a message which is an empty string. The translation of that is normally also an empty string, so it wasn't noticed, but it fails when a missing translation throws.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160437649
diff --git a/lib/message_lookup_by_library.dart b/lib/message_lookup_by_library.dart
index 7ef2a8d..66b93fd 100644
--- a/lib/message_lookup_by_library.dart
+++ b/lib/message_lookup_by_library.dart
@@ -33,13 +33,13 @@
/// Caches the last messages that we found
MessageLookupByLibrary _lastLookup;
- /// Look up the message with the given [name] and [locale] and return
- /// the translated version with the values in [args] interpolated.
- /// If nothing is found, return [message_str]. The [desc] and [examples]
- /// parameters are ignored
+ /// Look up the message with the given [name] and [locale] and return the
+ /// translated version with the values in [args] interpolated. If nothing is
+ /// found, return the result of [ifAbsent] or [message_str]. The
+ /// [desc] and [examples] parameters are ignored
String lookupMessage(
String message_str, String locale, String name, List args, String meaning,
- {MessageIfAbsent ifAbsent: _useOriginal}) {
+ {MessageIfAbsent ifAbsent}) {
// If passed null, use the default.
var knownLocale = locale ?? Intl.getCurrentLocale();
var messages = (knownLocale == _lastLocale)
@@ -48,7 +48,7 @@
// If we didn't find any messages for this locale, use the original string,
// faking interpolations if necessary.
if (messages == null) {
- return ifAbsent(message_str, args);
+ return ifAbsent == null ? message_str : ifAbsent(message_str, args);
}
return messages.lookupMessage(message_str, locale, name, args, meaning,
ifAbsent: ifAbsent);
@@ -82,9 +82,6 @@
}
}
-/// The default ifAbsent method, just returns the message string.
-String _useOriginal(String message_str, List args) => message_str;
-
/// This provides an abstract class for messages looked up in generated code.
/// Each locale will have a separate subclass of this class with its set of
/// messages. See generate_localized.dart.