flutter localization

Supporting multiple languages is the best practice to connect with a large section of audiences. Let’s dive in detail to get your fullter app to support multiple languages.

Let’s add “flutter_localizations” package dependencies in pubspec.yaml file.

dependencies:
flutter:
    sdk: flutter
flutter_localizations:
    sdk: flutter

# To add assets to your application, add an assets section, like this:
assets:
- assets/lang/

en.json

{ “welcome”:“Hello, Welcome to Cloudstar Mohan” }

ta.json

{  “welcome”:”வணக்கம்,வருக ! வருக !” }
import 'package:flutter_localizations/flutter_localizations.dart';

@override
Widget build(BuildContext context) {
  return MaterialApp(
    localizationsDelegates: [
      GlobalMaterialLocalizations.delegate,
      GlobalWidgetsLocalizations.delegate,
      GlobalCupertinoLocalizations.delegate,
    ],
    supportedLocales: [
      const Locale('en', ''),
      const Locale('ta', ''),
    ],
     localeResolutionCallback: (locale, supportedLocales) {
    for (var supportedLocaleLanguage in supportedLocales) {
       if (supportedLocaleLanguage.languageCode == locale.languageCode && supportedLocaleLanguage.countryCode == locale.countryCode) {
            return supportedLocaleLanguage;
       }
   }
   return supportedLocales.first;
 },
    home: Home(),
  );
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s