compareTo abstract method
Compare locales for sorting.
This method implements Comparable interface to enable sorting of locale collections. Comparison is done hierarchically:
- First by language code
- Then by country code (empty treated as empty string)
- Finally by variant (empty treated as empty string)
Returns:
- Negative value if this locale comes before
other - Zero if locales are equal
- Positive value if this locale comes after
other
Example:
final locales = [
Locale('fr', 'FR'),
Locale('en', 'US'),
Locale('en', 'CA'),
];
locales.sort((a, b) => a.compareTo(b));
// Result: [en-CA, en-US, fr-FR]
Implementation
int compareTo(Locale other);