Repository: aleksanderwozniak/table_calendar

Issue:
Customizing Date Format When Setting Locale to 'ko_KR'
Hello~

If I set **locale to 'ko_KR'**, dates in the calendar will be displayed with a '일' appended to them.
ex. 1일, 2일, 3일

![cal](https://github.com/aleksanderwozniak/table_calendar/assets/7288946/3627a49c-ef5f-408f-8445-0c9a6baaff67)


I want to set the header to 'ko_KR' to display the day of the week in Korean, and remove the '일' from the date.

Thank you.




Discussion: I agree, I'm getting that letter and it's preventing me from upgrading the version.
Hey, thanks for reporting this. I'll add a proper solution with next release, but for now as a workaround you can just use version 3.1.0.
> Hey, thanks for reporting this. I'll add a proper solution with next release, but for now as a workaround you can just use version 3.1.0.

Thanks!

I temporarily fixed the issue with the code below
- To set locale : 'en_US'
- To set dowTextFormatter and titleTextFormatter to ko_KR

```
TableCalendar(
  locale: 'en_US', 
  daysOfWeekStyle: DaysOfWeekStyle(
    dowTextFormatter: (date, locale) => DateFormat.E('ko_KR').format(date)[0],
	...
  ),
  headerStyle: HeaderStyle(
    titleTextFormatter: (date, locale) => DateFormat('yyyy년 M월', 'ko_KR').format(date),
    ...
  ),
  ...
```

Fix patch:
diff --git a/lib/src/customization/calendar_style.dart b/lib/src/customization/calendar_style.dart
index c052540b..abc00151 100644
--- a/lib/src/customization/calendar_style.dart
+++ b/lib/src/customization/calendar_style.dart
@@ -2,6 +2,7 @@
 // SPDX-License-Identifier: Apache-2.0
 
 import 'package:flutter/widgets.dart';
+import 'package:table_calendar/table_calendar.dart';
 
 /// Class containing styling and configuration for `TableCalendar`'s content.
 class CalendarStyle {
@@ -151,6 +152,15 @@ class CalendarStyle {
   /// Padding for the internal `Table` widget.
   final EdgeInsets tablePadding;
 
+  /// Use to customize the text within each day cell.
+  /// Defaults to `'${date.day}'`, to show just the day number.
+  ///
+  /// Example usage:
+  /// ```dart
+  /// dayTextFormatter: (date, locale) => DateFormat.d(locale).format(date),
+  /// ```
+  final TextFormatter? dayTextFormatter;
+
   /// Creates a `CalendarStyle` used by `TableCalendar` widget.
   const CalendarStyle({
     this.isTodayHighlighted = true,
@@ -227,6 +237,7 @@ class CalendarStyle {
     this.rowDecoration = const BoxDecoration(),
     this.tableBorder = const TableBorder(),
     this.tablePadding = const EdgeInsets.all(0),
+    this.dayTextFormatter,
   });
 }
 
diff --git a/lib/src/widgets/cell_content.dart b/lib/src/widgets/cell_content.dart
index a3276d5b..ba4d4ce7 100644
--- a/lib/src/widgets/cell_content.dart
+++ b/lib/src/widgets/cell_content.dart
@@ -60,7 +60,8 @@ class CellContent extends StatelessWidget {
       );
     }
 
-    final text = DateFormat.d(locale).format(day);
+    final text =
+        calendarStyle.dayTextFormatter?.call(day, locale) ?? '${day.day}';
     final margin = calendarStyle.cellMargin;
     final padding = calendarStyle.cellPadding;
     final alignment = calendarStyle.cellAlignment;


Test patch:
diff --git a/test/cell_content_test.dart b/test/cell_content_test.dart
index 40ade637..a147707e 100644
--- a/test/cell_content_test.dart
+++ b/test/cell_content_test.dart
@@ -11,6 +11,7 @@ import 'package:table_calendar/table_calendar.dart';
 Widget setupTestWidget(
   DateTime cellDay, {
   CalendarBuilders calendarBuilders = const CalendarBuilders(),
+  CalendarStyle calendarStyle = const CalendarStyle(),
   bool isDisabled = false,
   bool isToday = false,
   bool isWeekend = false,
@@ -23,8 +24,6 @@ Widget setupTestWidget(
   bool isTodayHighlighted = true,
   String? locale,
 }) {
-  final calendarStyle = CalendarStyle();
-
   return Directionality(
     textDirection: TextDirection.ltr,
     child: CellContent(
@@ -316,7 +315,23 @@ void main() {
   });
 
   group('CalendarBuilders Locale test:', () {
-    testWidgets('en locale', (tester) async {
+    testWidgets('en locale with default dayTextFormatter', (tester) async {
+      final locale = 'en';
+      initializeDateFormatting(locale, null);
+
+      final cellDay = DateTime.utc(2021, 7, 15);
+      await tester.pumpWidget(
+        setupTestWidget(
+          cellDay,
+          locale: locale,
+        ),
+      );
+
+      final dayFinder = find.text('${cellDay.day}');
+      expect(dayFinder, findsOneWidget);
+    });
+
+    testWidgets('en locale with custom dayTextFormatter', (tester) async {
       final locale = 'en';
       initializeDateFormatting(locale, null);
 
@@ -325,6 +340,10 @@ void main() {
         setupTestWidget(
           cellDay,
           locale: locale,
+          calendarStyle: CalendarStyle(
+            dayTextFormatter: (date, locale) =>
+                DateFormat.d(locale).format(date),
+          ),
         ),
       );
 
@@ -332,7 +351,7 @@ void main() {
       expect(dayFinder, findsOneWidget);
     });
 
-    testWidgets('ar locale', (tester) async {
+    testWidgets('ar locale with default dayTextFormatter', (tester) async {
       final locale = 'ar';
       initializeDateFormatting(locale, null);
 
@@ -344,6 +363,26 @@ void main() {
         ),
       );
 
+      final dayFinder = find.text('${cellDay.day}');
+      expect(dayFinder, findsOneWidget);
+    });
+
+    testWidgets('ar locale with custom dayTextFormatter', (tester) async {
+      final locale = 'ar';
+      initializeDateFormatting(locale, null);
+
+      final cellDay = DateTime.utc(2021, 7, 15);
+      await tester.pumpWidget(
+        setupTestWidget(
+          cellDay,
+          locale: locale,
+          calendarStyle: CalendarStyle(
+            dayTextFormatter: (date, locale) =>
+                DateFormat.d(locale).format(date),
+          ),
+        ),
+      );
+
       final dayFinder = find.text(DateFormat.d(locale).format(cellDay));
       expect(dayFinder, findsOneWidget);
     });