Articles in this section
Category / Section

How to Customize Localization in Flutter DataTable?

2 mins read

In this article, we will show you how to customize localization in Flutter DataTable.

Initialize the SfDataGrid widget with all the necessary properties. To add a custom culture beyond the 74 supported languages, extend the appropriate language class and override the required properties.

Step 1:

Create a dart file in your application and import the required packages.

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_core/localizations.dart';
import 'package:syncfusion_localizations/syncfusion_localizations.dart';
Step 2:

This has been depicted in the following example for the Estonian(et) language. Create a class for Estonian that extends the respective localization class (e.g., SfLocalizationsEt).
Base class format - SfLocalizations + Locale name.

/// The translations for  (`et`).
class CustomLocalizationsEt extends SfLocalizationsEt {
  CustomLocalizationsEt();

  @override
  String get cancelDataGridFilteringLabel => 'tühistada';
}

class SfLocalizationsEtDelegate extends LocalizationsDelegate<SfLocalizations> {
  static LocalizationsDelegate<SfLocalizations> delegate =
      SfLocalizationsEtDelegate();

  @override
  bool isSupported(Locale locale) => locale.languageCode == 'et';

  @override
  Future<SfLocalizations> load(Locale locale) {
    return SynchronousFuture<SfLocalizations>(CustomLocalizationsEt());
  }

  @override
  bool shouldReload(LocalizationsDelegate<SfLocalizations> old) => false;
}
Step 3:

Import the created dart file in your application and specify the localizationsDelegates, supportedLocales and locale. Then run your application.

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        SfLocalizationsEtDelegate.delegate,
      ],
      supportedLocales: const [
        Locale('en'),
        Locale('et'),
      ],
      locale: const Locale('et'),
      title: 'Syncfusion DataGrid Demo',
      theme: ThemeData(useMaterial3: false),
      home: const MyHomePage(),
    );
  }

View the GitHub sample here.

Conclusion
I hope you enjoyed learning how to customize localization in Flutter DataTable.
You can refer to our Flutter DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Flutter DataGrid Example 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 forums, Direct-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