getLocale method
Return the locale that this info object was created with.
Implementation
ILibLocale getLocale() {
final String jscode =
'JSON.stringify(new Country({locale: "$locale"}).getLocale())';
try {
final String result = ILibJS.instance.evaluate(jscode).stringResult;
// Attempt to parse JSON
final Map<String, dynamic> map =
json.decode(result) as Map<String, dynamic>;
// Extract values safely
final String language = _getStringValue(map, 'language');
final String region = _getStringValue(map, 'region');
final String script = _getStringValue(map, 'script');
final String variant = _getStringValue(map, 'variant');
return ILibLocale(language, region, variant, script);
} on FormatException catch (e) {
// Directly rethrow the original FormatException
throw FormatException('Failed to parse locale JSON: ${e.message}');
} catch (e) {
// Handle all other exceptions
throw Exception('An unexpected error occurred: $e');
}
}