The internationalization (i18n) library for Flutter

立即下载 ️⬇️

It lets you define translations for your content in different languages and switch between them easily.


Build Status License: MIT

The internationalization (i18n) library for Flutter.

It lets you define translations for your content in different languages and switch between them easily.

Package Pub Description
flutter_translate pub package The flutter_translate core package.
flutter_translate_preferences pub package Extension for automatically saving & restoring the selected locale.
flutter_translate_gen [WIP] Statically-typed localization keys generator for flutter_translate.


Table of Contents


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

  flutter_translate: ^1.4.0

Install packages from the command line (or from your editor):

flutter pub get


Import flutter_translate:

import 'package:flutter_translate/flutter_translate.dart';

Place the json localization files in a folder of your choice within the project.

By default flutter_translate will search for localization files in the assets/i18n directory in your project’s root.

Declare your assets localization directory in pubspec.yaml

    - assets/i18n

In the main function create the localization delegate and start the app, wrapping it with LocalizedApp

void main() async
  var delegate = await LocalizationDelegate.create(
        fallbackLocale: 'en_US',
        supportedLocales: ['en_US', 'es', 'fa']);

  runApp(LocalizedApp(delegate, MyApp()));

If the assets directory for the localization files is different than the default one (assets/i18n), you need to specify it:

 var delegate = await LocalizationDelegate.create(
        basePath: 'assets/i18n/'

Automatically save & restore the selected locale using the flutter_translate_preferences extension package

 var delegate = await LocalizationDelegate.create(
        preferences: TranslatePreferences()

Example MyApp:

class MyApp extends StatelessWidget {

  Widget build(BuildContext context) {

    var localizationDelegate = LocalizedApp.of(context).delegate;

    return LocalizationProvider(
      state: LocalizationProvider.of(context).state,
      child: MaterialApp(
        title: 'Flutter Translate Demo',
        localizationsDelegates: [
        supportedLocales: localizationDelegate.supportedLocales,
        locale: localizationDelegate.currentLocale,
        theme: ThemeData(primarySwatch:,
        home: MyHomePage(),


Translate a string:


Translate with arguments;

translate('your.localization.key', args: {'argName1': argValue1, 'argName2': argValue2});

Translate with pluralization:

translatePlural('plural.demo', yourNumericValue);


"plural": {
    "demo": {
        "0": "Please start pushing the 'plus' button.",
        "1": "You have pushed the button one time.",
        "else": "You have pushed the button  times."

Change the language:

Widget build(BuildContext context) {
    changeLocale(context, value);

You can view the full example here:

Github主页 👉bratan/flutter_translate