getMessage method
Retrieve a message for the given code.
Parameters:
code
: The message code to look upargs
: Optional arguments for placeholder substitutionlocale
: Optional locale for message resolution
Returns the resolved message string, or the code itself if not found.
Example:
// Simple message
final msg1 = getMessage('hello'); // "Hello"
// Message with parameters
final msg2 = getMessage('welcome', args: ['Alice']); // "Welcome Alice!"
// Message for specific locale
final msg3 = getMessage('hello', locale: Locale('es')); // "Hola"
Implementation
@override
String getMessage(String code, {List<Object>? args, Locale? locale, String? defaultMessage}) {
if(_messageSource == null) {
throw InvalidArgumentException("Message source has not been initialized yet");
}
return _messageSource!.getMessage(code, args: args, locale: locale, defaultMessage: defaultMessage);
}