validateLanguageCode static method
Validates language code format.
languageCode
is the language code to validate.
Returns true if the language code is valid.
Throws MessageException if the language code is invalid.
Implementation
static bool validateLanguageCode(String languageCode) {
if (languageCode.isEmpty) {
throw MessageException.invalidContent('Language code cannot be empty.');
}
// Basic format check (en_US, pt_BR, etc.)
final RegExp validCodePattern = RegExp(r'^[a-z]{2}(_[A-Z]{2})?$');
if (!validCodePattern.hasMatch(languageCode)) {
throw MessageException.invalidContent(
'Language code should be in format "xx" or "xx_YY".',
);
}
return true;
}