Localization in Flutter allows you to build apps adapting to different languages, regions, and cultures. Localizing your app allows you to reach a wider audience and provide a more personalized user experience. This guide will cover everything you need to know about localization in Flutter, including a detailed explanation of the process and example code.
Localization is the process of adapting an application’s interface and functionality to a specific language or culture. This includes translating text, formatting dates and numbers, and ensuring the app complies with the cultural norms of different regions.
Flutter provides robust support for localization through its flutter_localizations package, allowing you to localize text, dates, numbers, and more. You can also use the intl package to manage translations and formatting.
Related read: Localization with React Native i18n: A Comprehensive Guide
To start with localization in Flutter, you need to include the necessary packages in your pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
flutter_localizations: # Provides localization framework for Flutter
sdk: flutter
intl: ^0.17.0 # Helps with localization of strings, numbers, dates, etc.
The flutter_localizations package provides localization for Flutter’s built-in widgets. The intl package is used for message formatting and localization in your app.
In your MaterialApp, you need to define the locales (languages) that your app will support. Each locale is defined by a languageCode and optionally a countryCode.
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Localization',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
// Add custom localization delegate here later
],
supportedLocales: [
const Locale('en', ''), // English
const Locale('es', ''), // Spanish
const Locale('fr', ''), // French
],
home: MyHomePage(),
);
}
}
The localizationsDelegates list includes default Flutter localization delegates for widgets and material components.
Now you need to provide the actual translations for different languages. This can be done using JSON files that map keys to translated strings.
Create a directory for localization files under lib/l10n and add your JSON files for each language:
lib/l10n/en.json (English):
{
"title": "Welcome",
"message": "Hello, how are you?"
}
lib/l10n/es.json (Spanish):
{
"title": "Bienvenido",
"message": "Hola, ¿cómo estás?"
}
lib/l10n/fr.json (French):
{
"title": "Bienvenue",
"message": "Bonjour, comment ça va?"
}
Each key in these JSON files corresponds to a text string used in the app, while the value is the localized translation.
You need a helper class to load the JSON files and retrieve the localized strings. Create a new Dart file lib/localization.dart:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class AppLocalizations {
final Locale locale;
AppLocalizations(this.locale);
static AppLocalizations of(BuildContext context) {
return Localizations.of<AppLocalizations>(context, AppLocalizations);
}
static const LocalizationsDelegate<AppLocalizations> delegate = _AppLocalizationsDelegate();
Map<String, String> _localizedStrings;
Future<bool> load() async {
String jsonString = await rootBundle.loadString('lib/l10n/${locale.languageCode}.json');
Map<String, dynamic> jsonMap = json.decode(jsonString);
_localizedStrings = jsonMap.map((key, value) {
return MapEntry(key, value.toString());
});
return true;
}
String translate(String key) {
return _localizedStrings[key] ?? key;
}
}
class _AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
const _AppLocalizationsDelegate();
@override
bool isSupported(Locale locale) {
return ['en', 'es', 'fr'].contains(locale.languageCode);
}
@override
Future<AppLocalizations> load(Locale locale) async {
AppLocalizations localizations = AppLocalizations(locale);
await localizations.load();
return localizations;
}
@override
bool shouldReload(covariant LocalizationsDelegate<AppLocalizations> old) {
return false;
}
}
In this class:
In your MaterialApp, register the custom AppLocalizations delegate and update the localizationsDelegates list:
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'localization.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Localization',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
AppLocalizations.delegate, // Custom localization delegate
],
supportedLocales: [
const Locale('en', ''), // English
const Locale('es', ''), // Spanish
const Locale('fr', ''), // French
],
home: MyHomePage(),
);
}
}
This registers the AppLocalizations delegate and enables it to load the correct localization data for the current locale.
Now, instead of hardcoding strings, use the AppLocalizations class to retrieve localized text in your widgets:
import 'package:flutter/material.dart';
import 'localization.dart';
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var localization = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
title: Text(localization.translate('title')),
),
body: Center(
child: Text(localization.translate('message')),
),
);
}
}
To test how your app looks in different languages, you can manually change the locale in your app by overriding the Locale in the MaterialApp:
return MaterialApp(
locale: Locale('es', ''), // Spanish
...
);
Alternatively, if your device’s language settings change, Flutter will automatically load the appropriate localization.
The intl package is great for handling more complex scenarios, like pluralization and variables in strings.
Example:
en.json
{
"remainingEmails": "{count, plural, one {You have one email} other {You have {count} emails}}"
}
To display this in your app:
import 'package:intl/intl.dart';
String emailsMessage(int count) {
return Intl.plural(count,
one: 'You have one email',
other: 'You have $count emails',
locale: 'en',
);
}
Localization is a critical step in the development process, especially if your app is intended to reach a global audience. By localizing your Flutter app, you not only make it accessible to people from different linguistic and cultural backgrounds, but you also enhance user engagement and satisfaction by creating an experience that feels native to them.
In this guide, we’ve walked through the process of setting up localization in Flutter using JSON files, a custom localization class, and Flutter’s intl package for handling translations, pluralization, and formatting. We also covered how to integrate these translations into your widgets and offered best practices to ensure that your app is user-friendly across multiple languages.
By properly localizing your app, you’re doing more than just translating text — you’re respecting cultural differences, accommodating varying layouts (especially for RTL languages), and ensuring that every user, regardless of their language or region, can interact with your app seamlessly. Implementing localization can also make a significant difference in expanding your app’s reach to new markets, improving its adoption rate, and enhancing user retention.
Nandkishor Shinde is a React Native Developer with 5+ years of experience. With a primary focus on emerging technologies like React Native and React.js. His expertise spans across the domains of Blockchain and e-commerce, where he has actively contributed and gained valuable insights. His passion for learning is evident as he always remains open to acquiring new knowledge and skills.
The team at Mindbowser was highly professional, patient, and collaborative throughout our engagement. They struck the right balance between offering guidance and taking direction, which made the development process smooth. Although our project wasn’t related to healthcare, we clearly benefited...
Founder, Texas Ranch Security
Mindbowser played a crucial role in helping us bring everything together into a unified, cohesive product. Their commitment to industry-standard coding practices made an enormous difference, allowing developers to seamlessly transition in and out of the project without any confusion....
CEO, MarketsAI
I'm thrilled to be partnering with Mindbowser on our journey with TravelRite. The collaboration has been exceptional, and I’m truly grateful for the dedication and expertise the team has brought to the development process. Their commitment to our mission is...
Founder & CEO, TravelRite
The Mindbowser team's professionalism consistently impressed me. Their commitment to quality shone through in every aspect of the project. They truly went the extra mile, ensuring they understood our needs perfectly and were always willing to invest the time to...
CTO, New Day Therapeutics
I collaborated with Mindbowser for several years on a complex SaaS platform project. They took over a partially completed project and successfully transformed it into a fully functional and robust platform. Throughout the entire process, the quality of their work...
President, E.B. Carlson
Mindbowser and team are professional, talented and very responsive. They got us through a challenging situation with our IOT product successfully. They will be our go to dev team going forward.
Founder, Cascada
Amazing team to work with. Very responsive and very skilled in both front and backend engineering. Looking forward to our next project together.
Co-Founder, Emerge
The team is great to work with. Very professional, on task, and efficient.
Founder, PeriopMD
I can not express enough how pleased we are with the whole team. From the first call and meeting, they took our vision and ran with it. Communication was easy and everyone was flexible to our schedule. I’m excited to...
Founder, Seeke
We had very close go live timeline and Mindbowser team got us live a month before.
CEO, BuyNow WorldWide
If you want a team of great developers, I recommend them for the next project.
Founder, Teach Reach
Mindbowser built both iOS and Android apps for Mindworks, that have stood the test of time. 5 years later they still function quite beautifully. Their team always met their objectives and I'm very happy with the end result. Thank you!
Founder, Mindworks
Mindbowser has delivered a much better quality product than our previous tech vendors. Our product is stable and passed Well Architected Framework Review from AWS.
CEO, PurpleAnt
I am happy to share that we got USD 10k in cloud credits courtesy of our friends at Mindbowser. Thank you Pravin and Ayush, this means a lot to us.
CTO, Shortlist
Mindbowser is one of the reasons that our app is successful. These guys have been a great team.
Founder & CEO, MangoMirror
Kudos for all your hard work and diligence on the Telehealth platform project. You made it possible.
CEO, ThriveHealth
Mindbowser helped us build an awesome iOS app to bring balance to people’s lives.
CEO, SMILINGMIND
They were a very responsive team! Extremely easy to communicate and work with!
Founder & CEO, TotTech
We’ve had very little-to-no hiccups at all—it’s been a really pleasurable experience.
Co-Founder, TEAM8s
Mindbowser was very helpful with explaining the development process and started quickly on the project.
Executive Director of Product Development, Innovation Lab
The greatest benefit we got from Mindbowser is the expertise. Their team has developed apps in all different industries with all types of social proofs.
Co-Founder, Vesica
Mindbowser is professional, efficient and thorough.
Consultant, XPRIZE
Very committed, they create beautiful apps and are very benevolent. They have brilliant Ideas.
Founder, S.T.A.R.S of Wellness
Mindbowser was great; they listened to us a lot and helped us hone in on the actual idea of the app. They had put together fantastic wireframes for us.
Co-Founder, Flat Earth
Ayush was responsive and paired me with the best team member possible, to complete my complex vision and project. Could not be happier.
Founder, Child Life On Call
The team from Mindbowser stayed on task, asked the right questions, and completed the required tasks in a timely fashion! Strong work team!
CEO, SDOH2Health LLC
Mindbowser was easy to work with and hit the ground running, immediately feeling like part of our team.
CEO, Stealth Startup
Mindbowser was an excellent partner in developing my fitness app. They were patient, attentive, & understood my business needs. The end product exceeded my expectations. Thrilled to share it globally.
Owner, Phalanx
Mindbowser's expertise in tech, process & mobile development made them our choice for our app. The team was dedicated to the process & delivered high-quality features on time. They also gave valuable industry advice. Highly recommend them for app development...
Co-Founder, Fox&Fork