I want to display today's date in "Marathi" language.But the numbers from date are not displaying in Marathi language. I have written following code lines to achieve it. (flutter-3.0.4 stable)
DateTime currentDate = DateTime.now();
String todaysDate = DateFormat('d MMMM, yyyy', "mr_IN").format(currentDate);
Actual output is:
20 डिसेंबर, 2022
But I want to display:
२० डिसेंबर, २०२२
As we can see, numbers from date are not in Marathi language.
I have also wrote the below extension method but that also not resolve that issue:
extension ExtendedString on String {
String get toMarathi {
String dateInMarathi = this;
if (dateInMarathi.contains("0")) {
dateInMarathi = dateInMarathi.replaceAll("0", "०");
}
if (dateInMarathi.contains("1")) {
dateInMarathi = dateInMarathi.replaceAll("1", "१");
}
if (dateInMarathi.contains("2")) {
dateInMarathi = dateInMarathi.replaceAll("2", "२");
}
if (dateInMarathi.contains("3")) {
dateInMarathi = dateInMarathi.replaceAll("3", "३");
}
if (dateInMarathi.contains("4")) {
dateInMarathi = dateInMarathi.replaceAll("4", "४");
}
if (dateInMarathi.contains("5")) {
dateInMarathi = dateInMarathi.replaceAll("5", "५");
}
if (dateInMarathi.contains("6")) {
dateInMarathi = dateInMarathi.replaceAll("6", "६");
}
if (dateInMarathi.contains("7")) {
dateInMarathi = dateInMarathi.replaceAll("7", "७");
}
if (dateInMarathi.contains("8")) {
dateInMarathi = dateInMarathi.replaceAll("8", "८");
}
if (dateInMarathi.contains("9")) {
dateInMarathi = dateInMarathi.replaceAll("9", "९");
}
return dateInMarathi;
}
}
CodePudding user response:
Try the following code:
extension ExtendedString on String {
String toMarathi {
return this.replaceAll("0", "०").replaceAll("1", "१").replaceAll("2", "२").replaceAll("3", "३").replaceAll("4", "४").replaceAll("5", "५").replaceAll("6", "६").replaceAll("7", "७").replaceAll("8", "८").replaceAll("9", "९");
}
}
"${DateTime.now().day}, ${DateTime.now().month}, ${DateTime.now().year}".toMarathi()
CodePudding user response: