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, an Exception is thrown with a helpful error message.
Example:
final lang = validateLangCode('Ne'); // returns 'ne'
validateLangCode('xx'); // throws Exception
code: The language code to validate (case-insensitive).
Returns the normalized (lowercase) version of the code if valid.
Throws Exception if the code is not supported.
Implementation
String validateLangCode(String code) {
final normalized = code.toLowerCase();
if (!supportedLangCodes.contains(normalized)) {
throw Exception("❌ Unsupported language code: '$code'. "
"Please use a valid ISO-639 code (e.g. 'ne' for Nepali, 'fr' for French).");
}
return normalized;
}