simple_localization 1.1.1

simple_localization #

Implement localizations in your packages and applications simply.

import 'package:simple_localization/simple_localization.dart';

How to internationalize your app or package #

First, I recommend that you declare an enumeration with the message names to make it easier to find messages

enum WidgetMessages { message1, message2 }

Below is an example localization, with the translation of message1 andmessage2 into English, Spanish and Portuguese.

If the application language does not match the supported languages that are declared in supportedLocales, the default language entered indefaultLocale will be used.

class ExampleLocalizations extends SimpleLocalizations {
  static ExampleLocalizations of(BuildContext context) {
    return SimpleLocalizations.of<ExampleLocalizations>(context, (locale) => ExampleLocalizations(locale));

  ExampleLocalizations(Locale locale) : super(locale);

  Locale get defaultLocale => Locale('en');

  Iterable<Locale> get suportedLocales => [

  Map<dynamic, Map<dynamic, String>> get localizedValues => {
    'en': {
      WidgetMessages.message1: 'First message',
      WidgetMessages.message2: 'Second message',
    'es': {
      WidgetMessages.message1: 'Primer mensaje',
      WidgetMessages.message2: 'Segundo mensaje',
    'pt': {
      WidgetMessages.message1: 'Primeira mensagem',
      WidgetMessages.message2: 'Segunda mensagem',

/// This class is only needed if you are developing a package, and you want to
/// make it available to you to develop a way to customize messages.
class ExampleLocalizationsDelegate extends SimpleLocalizationsDelegate<ExampleLocalizations> {
  ExampleLocalizationsDelegate(customLocalization) : super(customLocalization);

Below will be shown how to get messages according to app location


It is not necessary to declare localization in localizationsDelegates of MaterialApp, but it is important that you enter supportedLocales to specify the languages supported by your application.

When specifying other locations (other than 'en'), you will need to add in the supportedLocales ofMaterialApp the locations GlobalMaterialLocalizations.delegate andGlobalWidgetsLocalizations.delegate, missing these locations will generate an application error.

In your pubspec.yaml add follow dependencie:

    sdk: flutter

And in your MaterialApp, add localizations in supportedLocales

  localizationsDelegates: [

Customize package locations #

It is often used in package internationalizations, when the developer needs to modify the default messages used in package, for that you need to extend the location of your package, and implement BasicLocalizationsDelegate.

First let's create the custom internationalization that will extend the default package location.

class CustomLocalization extends ExampleLocalizations {
  CustomLocalization(Locale locale) : super(locale);

  Map<dynamic, Map<dynamic, String>> get customValues => {
    'en': {
      WidgetMessages.message1: 'Custom first message',
      WidgetMessages.message2: 'Custom second message',
    'es': {
      WidgetMessages.message1: 'Primer mensaje personalizado',
      WidgetMessages.message2: 'Segundo mensaje personalizado',
    'pt': {
      WidgetMessages.message1: 'Primeira mensagem personalizada',
      WidgetMessages.message2: 'Segunda mensagem personalizada',

And finally, inform the delegate in localizationsDelegates of your apps MaterialApp.

  localizationsDelegates: [
    ExampleLocalizationsDelegate((locale) => CustomLocalization(locale)),

1.1.1 #

  • Fixed class name 'BasicLocalizationsDelegate' for SimpleLocalizationsDelegate

1.1.0 #

  • Added customValues in SimpleLocalizations to allow you to customize just a few messages.

1.0.0 #

  • Initial version


example_localization #

Sample app to show how simple_localization package works


Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  simple_localization: ^1.1.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:simple_localization/simple_localization.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health suggestions

Format lib/classes/simple_localization.dart.

Run flutter format to format lib/classes/simple_localization.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
pedantic ^1.8.0