Articles in this section
Category / Section

How to localize the Flutter Calendar

3 mins read

In the Flutter Event Calendar, you can change the locale of the flutter calendar and customize strings using the `locale` property of MaterialApp widget.

Step 1: Use `SfGlobalLocalizations.delegate` in the `localizationsDelegate` for custom string localization (NoEvents, NoSelectedDate). For localization, you need to add the supported locales to an array and using any one of the supported locales, you can set the locale for the calendar.

      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        SfGlobalLocalizations.delegate,
 
      ],
      supportedLocales: [
        const Locale('en'), 
        const Locale('zh'), 
        const Locale('he'), 
        const Locale('ru'), 
        const Locale('fr', 'BE'),
        const Locale('fr', 'CA'),
        const Locale('ja'),
        const Locale('de'),
        const Locale('hi'), 
        const Locale('ar'),
      ],
      locale: const Locale('zh'),

 

Step 2: Find the complete code snippet for localization.

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';
import 'package:syncfusion_localizations/syncfusion_localizations.dart';
 
void main() => runApp(LocalizationSupport());
 
class LocalizationSupport extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        SfGlobalLocalizations.delegate,
      ],
      supportedLocales: [
        const Locale('en'),
        const Locale('zh'),
        const Locale('he'),
        const Locale('ru'),
        const Locale('fr', 'BE'),
        const Locale('fr', 'CA'),
        const Locale('ja'),
        const Locale('de'),
        const Locale('hi'),
        const Locale('ar'),
      ],
      locale: const Locale('zh'),
      debugShowCheckedModeBanner: false,
      home: CustomStringLocale(),
    );
  }
}
 
class CustomStringLocale extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => ScheduleExample();
}
 
class ScheduleExample extends State<CustomStringLocale> {
  CalendarView _calendarView;
 
  @override
  void initState() {
    _calendarView = CalendarView.month;
    super.initState();
  }
 
  @override
  Widget build(BuildContext context) {
    return (Scaffold(
      body: Column(
        children: <Widget>[
          Expanded(
            child: SfCalendar(
              view: _calendarView,
              monthViewSettings: MonthViewSettings(showAgenda: true),
              dataSource: _getCalendarDataSource(),
            ),
          ),
        ],
      ),
    ));
  }
}
 
_AppointmentDataSource _getCalendarDataSource() {
  List<Appointment> appointments = <Appointment>[];
  appointments.add(Appointment(
    startTime: DateTime.now(),
    endTime: DateTime.now().add(Duration(minutes: 10)),
    subject: '会议',
    color: Colors.blue,
    startTimeZone: '',
    endTimeZone: '',
  ));
 
  return _AppointmentDataSource(appointments);
}
 
class _AppointmentDataSource extends CalendarDataSource {
  _AppointmentDataSource(List<Appointment> source) {
    appointments = source;
  }
}

 

View the GitHub sample here

 

No selected date

selected date

with events

 

Conclusion

I hope you enjoyed learning about how to localize the Flutter Calendar.

You can refer to our  Flutter Calender feature tour page to know about its other groundbreaking feature representations. You can also explore our Flutter Calendar documentation to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied