Category / Section
How to localize the Flutter Calendar
2 mins read
In the Flutter Event Calendar, you can change the locale of the flutter calendar and custom strings using the `locale` property of MaterialApp widget.
Step 1
Using `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 3
Please 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;
}
}
Did not find the solution
Contact Support