formatedLanguageCode property

String get formatedLanguageCode

Returns a formatted language code, optionally including a country code.

Special handling for Chinese ("zh") locales: If the country code is missing, it defaults to "CN".

Examples:

Locale('en', 'US').formatedLanguageCode; // "en"
Locale('zh').formatedLanguageCode;       // "zh_CN"
Locale('zh', 'TW').formatedLanguageCode; // "zh_TW"

Implementation

String get formatedLanguageCode {
  String l = languageCode;
  if (l == "zh") {
    String? c = countryCode?.toUpperCase();
    if (c == null || c.isEmpty) c = "CN";
    l = "${l}_$c";
  }
  return l;
}