validateLangCode function
Validates the given code
as a supported language code.
Converts code
to lowercase and checks if it exists in supportedLangCodes.
If the code is invalid, throws UnsupportedLanguageException.
Example:
final lang = validateLangCode('Ne'); // returns 'ne'
validateLangCode('xx'); // throws UnsupportedLanguageException
code
: The language code to validate (case-insensitive).
Returns the normalized (lowercase) version of the code if valid.
Throws UnsupportedLanguageException if the code is not supported.
Implementation
String validateLangCode(String code) {
final normalized = code.toLowerCase();
if (!supportedLangCodes.contains(normalized)) {
throw UnsupportedLanguageException(code);
}
return normalized;
}