convertNumberToLocale static method
Converts a number to the specified locale's numeral system يحول رقماً إلى نظام الترقيم الخاص باللغة المحددة
Supported locales:
- 'ar': Arabic (٠١٢٣٤٥٦٧٨٩)
- 'bn': Bengali (০১২৩৪৫৬৭৮৯)
- 'ur': Urdu (۰۱۲۳۴۵۶۷۸۹)
- 'en', 'id', 'ms', 'fil', 'tr': Western digits (0123456789)
Implementation
static String convertNumberToLocale(int? number, String locale) {
if (number == null) return '';
String numberString = number.toString();
List<String>? numerals = _getNumeralsForLocale(locale);
if (numerals == null) return numberString;
StringBuffer result = StringBuffer();
for (int i = 0; i < numberString.length; i++) {
String char = numberString[i];
if (char == '-') {
result.write('-'); // Keep negative sign
} else {
int digit = int.tryParse(char) ?? 0;
result.write(numerals[digit]);
}
}
return result.toString();
}