dalocale 1.7.0

Dalocale #

A Flutter package to easily support internationalization and localization in your project.

Installation #

Add the following dependencies to your pubspec.yaml:

    sdk: flutter 

  dalocale: ^1.7.0

Example #

Creating localization files #

Create a folder to store all the localizations in json format. The name of each file should match the locale that is representing. For example:

└─ assets
   └─ i18n
      ├─ en.json
      └─ es.json

Each localization file must contain a single json object with all the keys and values. For example:

    "greetings": "Hello, world!",
    "welcome.back": "Welcome back: %1$s"

In the previous example, the key welcome.back contains a value with a parameter.

Parameters #

Parameters inside of localized text must be declared as %index$format, where:

  • index: the position of the parameter in the text (starting from 1)
  • format: the format of the parameter (e.g. s, d, f, etc.)

Generating Dart code #

To generate the Dart file containing all the localizations, run the following command:

flutter pub pub run dalocale:dalocale.dart INPUT_FOLDER OUTPUT_FILE [DEFAULT_LOCALE] [LIB_FOLDER]

For example:

flutter pub pub run dalocale:dalocale.dart ./assets/i18n/ ./lib/foo/bar/localizations.dart en ./lib

The LIB_FOLDER parameter is used to check for unused keys in the project.

Using generated code #

In you main.dart file, add the auto-generated classes CustomLocalizationsDelegate and Localized to the app:

import 'package:flutter/material.dart';
import 'package:flutter_library/foo/bar/localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

void main() {

class MyApp extends StatelessWidget {
  Widget build(BuildContext context) {
    return MaterialApp(
      home: ...,
      localizationsDelegates: const [
      supportedLocales: Localized.locales,

You can use the class Localized to have access to all the entries declared in the json files:


To get the current active locale in the app:

Locale locale = Localized.current;

[1.0.0] - 2019-06-23

  • First version

[1.2.1] - 2019-06-23

  • Renamed main script to dalocale.dart

[1.3.0] - 2019-06-24

  • Improved generator script

[1.3.1] - 2019-06-25

  • Fixed bug escaping single quotes

[1.4.0] - 2019-06-27

  • Added lint rules

[1.5.0] - 2019-06-30

  • Changed parameter system

[1.6.0] - 2019-07-27

  • Added field for current locale

[1.7.0] - 2019-08-19

  • Added check for unused keys


Example #

Example available in the main README.

Use this package as a library

1. Depend on it

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

  dalocale: ^1.7.0

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:dalocale/dalocale.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 issues and suggestions

Document public APIs. (-1 points)

1 out of 1 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
flutter 0.0.0
flutter_localizations 0.0.0
path ^1.6.2 1.6.4
Transitive dependencies
collection 1.14.11 1.14.12
intl 0.16.0 0.16.1
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies