Translation and Internationalization (i18n) for Flutter

i18n_extension .Non-boilerplate Translation and Internationalization (i18n) for Flutter

Start with a widget with some text in it:

Text("Hello, how are you?")

Translate it simply by adding .i18n to the string:

Text("Hello, how are you?".i18n)

Or you can also use identifiers, as you prefer:

Text(greetings.i18n)

If the current locale is 'pt_BR', then the text in the screen will be "Olá, como vai você?", the Portuguese translation to the above text. And so on for any other locales you want to support.

You can also provide different translations depending on modifiers, for example plural quantities:

print("There is 1 item".plural(0)); // Prints 'There are no items'
print("There is 1 item".plural(1)); // Prints 'There is 1 item'
print("There is 1 item".plural(2)); // Prints 'There are 2 items'

And you can invent your own modifiers according to any conditions. For example, some languages have different translations for different genders. So you could create gender versions for Gender modifiers:

print("There is a person".gender(Gender.male)); // Prints 'There is a man'
print("There is a person".gender(Gender.female)); // Prints 'There is a woman'
print("There is a person".gender(Gender.they)); // Prints 'There is a person'

Also, interpolating strings is easy, with the fill method:

// Prints 'Hello John, this is Mary' in English.
// Prints 'Olá John, aqui é Mary' in Portuguese.
print("Hello %s, this is %s".i18n.fill(["John", "Mary"]));

See it working

Try running the example.

Good for simple or complex apps

I'm always interested in creating packages to reduce boilerplate. For example, async_redux is about Redux without boilerplate, and align_positioned is about creating layouts using fewer widgets. This current package is also about reducing boilerplate for translations, so it doesn't do anything you can't already do with plain old Localizations.of(context).

That said, this package is meant both for the one person app developer, and the big company team. It has you covered in all stages of your translation efforts:

When you create your widgets, it makes it easy for you to define which strings should be translated, by simply adding .i18n to them. These strings are called "translatable strings".

When you want to start your translation efforts, it can automatically list for you all strings that need translation. If you miss any strings, or if you later add more strings or modify some of them, it will let you know what changed and how to fix it.

You can then provide your translations manually, in a very easy-to-use format.

Or you can easily integrate it with professional translation services, importing it from, or exporting it to any format you want.

Setup

Wrap your widget tree with the I18n widget, below the MaterialApp, together with the localizationsDelegates and the supportedLocales:

import 'package:i18n_extension/i18n_widget.dart';
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', "US"),
        const Locale('pt', "BR"),
      ],
      home: I18n(child: ...)
  );
}

Note: To be able to import flutter_localizations.dart you must add this to your pubspec.yaml:

dependencies:
  flutter_localizations:
    sdk: flutter

  i18n_extension: ^4.1.0

The code home: I18n(child: ...) shown above will translate your strings to the current system locale. Or you can override it with your own locale, like this:

I18n(
  initialLocale: Locale("pt", "BR"),
  child: ...

Note: Don't ever put translatable strings in the same widget where you declared the I18n widget, since they may not respond to future locale changes. For example, this is a mistake:

Widget build(BuildContext context) {
  return I18n(
    child: Scaffold(
      appBar: AppBar(title: Text("Hello there".i18n)),
      body: MyScreen(),
  );
}

You may put translatable strings in any widgets down the tree.

A quick recap of Dart locales

The correct way to create a Locale is to provide a language code (usually 2 or 3 lowercase letters) and a country code (usually 2 uppercase letters), as two separate Strings.

For example:

var locale = Locale("en", "US");

print(locale); // Prints `en_US`.
print(locale.languageCode); // Prints `en`.

You can, if you want, omit the country code:

var locale = Locale("en");

print(locale); // Prints `en`.
print(locale.languageCode); // Prints `en`.

But you cannot provide language code and country code as a single String. This is wrong:

// This will create a language called "en_US" and no country code.
var locale = Locale("en_US");

print(locale); // Prints `en_US`.
print(locale.languageCode); // Also prints `en_US`.

To help avoiding this mistake, the i18n_extension may throw an error if your language code contains underscores.

Translating a widget

When you create a widget that has translatable strings, add this default import to the widget's file:

import 'package:i18n_extension/default.i18n.dart';

This will allow you to add .i18n and .plural() to your strings, but won't translate anything.

When you are ready to create your translations, you must create a dart file to hold them. This file can have any name, but I suggest you give it the same name as your widget and change the termination to .i18n.dart.

For example, if your widget is in file my_widget.dart, the translations could be in file my_widget.i18n.dart

You must then remove the previous default import, and instead import your own translation file:

import 'my_widget.i18n.dart';

Your translation file itself will be something like this:

import 'package:i18n_extension/i18n_extension.dart';

extension Localization on String {

  static var _t = Translations("en_us") +
    {
      "en_us": "Hello, how are you?",
      "pt_br": "Olá, como vai você?",
      "es": "¿Hola! Cómo estás?",
      "fr": "Salut, comment ca va?",
      "de": "Hallo, wie geht es dir?",
    };

  String get i18n => localize(this, _t);
}

The above example shows a single translatable string, translated to American English, Brazilian Portuguese, and general Spanish, French and German.

You can, however, translate as many strings as you want, by simply adding more translation maps:

import 'package:i18n_extension/i18n_extension.dart';

extension Localization on String {

    static var _t = Translations("en_us") +
        {
          "en_us": "Hello, how are you?",
          "pt_br": "Olá, como vai você?",
        } +
        {
          "en_us": "Hi",
          "pt_br": "Olá",
        } +
        {
          "en_us": "Goodbye",
          "pt_br": "Adeus",
        };

  String get i18n => localize(this, _t);
}

Strings themselves are the translation keys

The locale you pass in the Translations() constructor is called the default locale. For example, in Translations("en_us") the default locale is en_us. All translatable strings in the widget file should be in the language of that locale.

The strings themselves are used as keys when searching for translations to the other locales. For example, in the Text below, "Hello, how are you?" is both the translation to English, and the key to use when searching for its other translations:

Text("Hello, how are you?".i18n)

If any translation key is missing from the translation maps, the key itself will be used, so the text will still appear in the screen, untranslated.

If the translation key is found, it will choose the language according to the following rules:

It will use the translation to the exact current locale, for example en_us.

If this is absent, it will use the translation to the general language of the current locale, for example en.

If this is absent, it will use the translation to any other locale with the same language, for example en_uk.

If this is absent, it will use the value of the key in the default language.

If this is absent, it will use the key itself as the translation.

Try running the example using strings as translation keys.

Or you can, instead, use identifiers as translation keys

Instead of:

"Hello there".i18n

You can also do:

greetings.i18n

To that end, you can use the Translations.from constructor:

const appbarTitle = "appbarTitle";
const greetings = "greetings";

extension Localization on String {
    
  static final _t = Translations.from("en_us", {
    appbarTitle: {
      "en_us": "i18n Demo",
      "pt_br": "Demonstração i18n",
    },
    greetings: {
      "en_us": "Helo there",
      "pt_br": "Olá como vai",
    },    
  });

  String get i18n => localize(this, _t);    
}

Try running the example using identifiers as translation keys.

Managing keys

Other translation packages force you to define identifier keys for each translation, and use those. For example, an identifier key could be helloHowAreYou or simply greetings. And then you could access it like this: MyLocalizations.of(context).greetings.

However, having to define identifiers is not only a boring task, but it also makes it more difficult to remember the exact text of the widget.

With i18n_extension you can still use identifier keys, but you can also simply type the text you want and add .i18n to them.

If some string is already translated, and you later change it in the widget file, this will break the link between the key and the translation map. However, i18n_extension is smart enough to let you know when that happens, so it's easy to fix. You can even add this check to tests, as to make sure all translations are linked and complete.

When you run your app or tests, each key not found will be recorded to the static set Translations.missingKeys. And if the key is found but there is no translation to the current locale, it will be recorded to Translations.missingTranslations.

You can manually inspect those sets to see if they're empty, or create tests to do that automatically, for example:

expect(Translations.missingKeys, isEmpty);
expect(Translations.missingTranslations, isEmpty);

Note: You can disable the recording of missing keys and translations by doing:

Translations.recordMissingKeys = false;
Translations.recordMissingTranslations = false;

Another thing you may do, if you want, is to set up callbacks that the i18n_extension package will call whenever it detects a missing translation. You can then program these callbacks to throw errors if any translations are missing, or log the problem, or send emails to the person responsible for the translations.

To do that, simply inject your callbacks into Translations.missingKeyCallback and Translations.missingTranslationCallback.

For example:

Translations.missingTranslationCallback =
  (key, locale) =>
    throw TranslationsException("There are no translations in '$locale' for '$key'.");

Defining translations by locale instead of by key

As explained, by using the Translations() constructor you define each key and then provide all its translations at the same time. This is the easiest way when you are doing translations manually, for example, when you speak English and Spanish and are creating yourself the translations to your app.

However, in other situations, such as when you are hiring professional translation services or crowdsourcing translations, it may be easier if you can provide the translations by locale/language, instead of by key. You can do that by using the Translations.byLocale() constructor.

static var _t = Translations.byLocale("en_us") +
    {
      "en_us": {
        "Hi.": "Hi.",
        "Goodbye.": "Goodbye.",
      },
      "es_es": {
        "Hi.": "Hola.",
        "Goodbye.": "Adiós.",
      }
    };

You can also add maps using the + operator:

static var _t = Translations.byLocale("en_us") +
    {
      "en_us": {
        "Hi.": "Hi.",
        "Goodbye.": "Goodbye.",
      },
    } +
    {
      "es_es": {
        "Hi.": "Hola.",
        "Goodbye.": "Adiós.",
      }
    };

Note above, since "en_us" is the default locale you don't need to provide translations for those.

Combining translations

To combine translations you can use the * operator. For example:

var t1 = Translations("en_us") +
    {
      "en_us": "Hi.",
      "pt_br": "Olá.",
    };

var t2 = Translations("en_us") +
    {
      "en_us": "Goodbye.",
      "pt_br": "Adeus.",
    };

var translations = t1 * t2;

print(localize("Hi.", translations, locale: "pt_br");
print(localize("Goodbye.", translations, locale: "pt_br");

Translation modifiers

Sometimes you have different translations that depend on a number quantity. Instead of .i18n you can use .plural() and pass it a number. For example:

int numOfItems = 3;
return Text("You clicked the button %d times".plural(numOfItems));

This will be translated, and if the translated string contains %d it will be replaced by the number.

Then, your translations file should contain something like this:

static var _t = Translations("en_us") +
  {
    "en_us": "You clicked the button %d times"
        .zero("You haven't clicked the button")
        .one("You clicked it once")
        .two("You clicked a couple times")
        .many("You clicked %d times")
        .times(12, "You clicked a dozen times"),
    "pt_br": "Você clicou o botão %d vezes"
        .zero("Você não clicou no botão")
        .one("Você clicou uma única vez")
        .two("Você clicou um par de vezes")
        .many("Você clicou %d vezes")
        .times(12, "Você clicou uma dúzia de vezes"),
  };

String plural(int value) => localizePlural(value, this, _t);

Or, if you want to define your translations by locale:

static var _t = Translations.byLocale("en_us") +
    {
      "en_us": {
        "You clicked the button %d times": 
          "You clicked the button %d times"
            .zero("You haven't clicked the button")
            .one("You clicked it once")
            .two("You clicked a couple times")
            .many("You clicked %d times")
            .times(12, "You clicked a dozen times"),
      },
      "pt_br": {
        "You clicked the button %d times": 
          "Você clicou o botão %d vezes"
            .zero("Você não clicou no botão")
            .one("Você clicou uma única vez")
            .two("Você clicou um par de vezes")
            .many("Você clicou %d vezes")
            .times(12, "Você clicou uma dúzia de vezes"),
      }
    };

The plural modifiers you can use are zero, one, two, three, four, five, six, ten, times (for any number of elements, except 0, 1 and 2), many (for any number of elements, except 1, including 0) , zeroOne (for 0 or 1 elements), and oneOrMore (for 1 and more elements).

Also, according to a Czech speaker, there must be a special modifier for 2, 3 and 4. To that end you can use the twoThreeFour modifier.

Note: It will use the most specific plural modifier. For example, .two is more specific than .many. If no applicable modifier can be found, it will default to the unversioned string. For example, this: "a".zero("b").four("c:") will default to "a" for 1, 2, 3, or more than 5 elements.

Custom modifiers

You can actually create any modifiers you want. For example, some languages have different translations for different genders. So you could create .gender() that accepts Gender modifiers:

enum Gender {they, female, male}

int gnd = Gender.female;
return Text("There is a person".gender(gnd));

Then, your translations file should use .modifier() and localizeVersion() like this:

static var _t = Translations("en_us") +
  {
    "en_us": "There is a person"
        .modifier(Gender.male, "There is a man")
        .modifier(Gender.female, "There is a woman")
        .modifier(Gender.they, "There is a person"),
    "pt_br": "Há uma pessoa"
        .modifier(Gender.male, "Há um homem")
        .modifier(Gender.female, "Há uma mulher")
        .modifier(Gender.they, "Há uma pessoa"),
  };

String gender(Gender gnd) => localizeVersion(gnd, this, _t);

Interpolation

Your translations file may declare a fill method to do interpolations:

static var _t = Translations("en_us") +
  {
    "en_us": "Hello %s, this is %s",
    "pt_br": "Olá %s, aqui é %s",
  };

String get i18n => localize(this, _t);

String fill(List<Object> params) => localizeFill(this, params);

Then you may use it like this:

print("Hello %s, this is %s".i18n.fill(["John", "Mary"]));

The above code will print Hello John, this is Mary if the locale is English, or Olá John, aqui é Mary if it's Portuguese.

It uses the sprintf package internally. I don't know how closely it follows the C sprintf specification, but here it is.

Direct use of translation objects

If you have a translation object you can use the localize function directly to perform translations:

var translations = Translations("en_us") +
    {
      "en_us": "Hi",
      "pt_br": "Olá",
    };

// Prints "Hi".
print(localize("Hi", translations, locale: "en_us");

// Prints "Olá".
print(localize("Hi", translations, locale: "pt_br");

// Prints "Hi".
print(localize("Hi", translations, locale: "not valid");

Changing the current locale

To change the current locale, do this:

I18n.of(context).locale = Locale("pt", "BR");

To return the current locale to the system default, do this:

I18n.of(context).locale = null;

Note: The above will change the current locale only for the i18n_extension, and not for Flutter as a whole.

Reading the current locale

To read the current locale, do this:

// Both ways work:
Locale locale = I18n.of(context).locale;
Locale locale = I18n.locale;

// Or get the locale as a lowercase string. Example: "en_us".
String localeStr = I18n.localeStr;

// Or get the language of the locale, lowercase. Example: "en".
String language = I18n.language;

Observing locale changes

There is a global static callback you can use to observe locale changes:

I18n.observeLocale = 
  ({required Locale oldLocale, required Locale newLocale}) 
      => print("Changed from $oldLocale to $newLocale.");

Importing and exporting

This package is optimized so that you can easily create and manage all of your translations yourself, by hand.

However, for large projects with big teams you probably need to follow a more involved process:

Export all your translatable strings to files in some external format your professional translator, or your crowdsourcing tool uses (see formats below).

Continue developing your app while waiting for the translations.

Import the translation files into the project and test the app in each language you added.

Repeat the process as needed, translating just the changes between each app revision. As necessary, perform additional localization steps yourself.

Formats

The following formats may be used with translations:

PO: https://poedit.net

JSON: Can be used, however it lacks specific features for translation, like plurals and gender.

ARB: This is based on JSON, and is the default format for Flutter localizations. https://github.com/google/app-resource-bundle/wiki/ApplicationResourceBundleSpecification

ICU: https://format-message.github.io/icu-message-format-for-translators/

XLIFF: This is based in XML. https://en.wikipedia.org/wiki/XLIFF

CSV: You can open this with Excel, save it in .XLSX and edit it there. However, beware not to export it back to CSV with the wrong settings (using something else than UTF-8 as encoding). https://en.wikipedia.org/wiki/Comma-separated_values

YAML: Can be used, however it lacks specific features for translation, like plurals and gender.

Importing

Currently, only .PO and .JSON importers are supported out-of-the-box.

Note: Those importers were contributed by Johann Bauer. If you want to help creating importers for any of the other formats above, please PR here: https://github.com/marcglasberg/i18n_extension.

Add your translation files as assets to your app in a directory structure like this:

app
 \_ assets
    \_ locales
       \_ de.po
       \_ fr.po
        ...

Then you can import them using GettextImporter or JSONImporter:

import 'package:i18n_extension/io/import.dart';
import 'package:i18n_extension/i18n_extension.dart';

class MyI18n {
  static TranslationsByLocale translations = Translations.byLocale("en");

  static Future<void> loadTranslations() async {
    translations +=
        await GettextImporter().fromAssetDirectory("assets/locales");
  }
}

extension Localization on String {
  String get i18n => localize(this, MyI18n.translations);
  String plural(int value) => localizePlural(value, this, MyI18n.translations);
  String fill(List<Object> params) => localizeFill(this, params);
}

For usage in main.dart, see here.

Note: When using .po files, make sure not to include the country code, because the locales are generated from the filenames which don't contain the country code and if you'd include the country codes, you'll get errors like this: There are no translations in 'en_us' for "Hello there".

Note: If you need to import any other custom format, remember importing is easy to do because the Translation constructors use maps as input. If you can generate a map from your file format, you can then use the Translation() or Translation.byLocale() constructors to create the translation objects.

The GetStrings exporting utility

An utility script to automatically export all translatable strings from your project was contributed by Johann Bauer. Simply run flutter pub run i18n_extension:getstrings in your project root directory and you will get a list of strings to translate in strings.json. This file can then be sent to your translators or be imported in translation services like Crowdin, Transifex or Lokalise. You can use it as part of your CI pipeline in order to always have your translation templates up to date.

Note the tool simply searches the source code for strings to which getters like .i18n are applied. Since it is not very smart, you should not make it too hard:

print("Hello World!".i18n); // This would work.

// But the tool would not be able to spot this 
// since it doesn't execute the code.
var x = "Hello World";
print(x.i18n);

Other ways to export

As previously discussed, i18n_extension will automatically list all keys into a map if you use some unknown locale, run the app, and manually or automatically go through all the screens. For example, create a Greek locale if your app doesn't have Greek translations, and it will list all keys into Translations.missingTranslationCallback.

Then you can read from this map and create your exported file. There is also this package that goes through all screens automatically.

FAQ

Q: Do I need to maintain the translation files as Dart files?

A: Not really. You do have a Dart file that creates a Translation object, yes, and this object is optimized for easily creating translations by hand. But it creates them from maps. So if you can create maps from some file you can use that file. For example, a simple code generator that reads .json und outputs Dart maps would do the job: var _t = Translations("en_us") + readFromJson("myfile.json").


 

Q: How do you handle changing the locale? Does the I18n class pick up changes to the locale automatically or would you have to restart the app?

A: It should pick changes to the locale automatically. Also, you can change the locale manually at any time by doing I18n.of(context).locale = Locale("pt", "BR");.


 

Q: What's the point of importing 'default.i18n.dart'?

A: This is the default file to import from your widgets. It lets the developer add .i18n to any strings they want to mark as being a "translatable string". Later, someone will have to remove this default file and add another one with the translations. You basically just change the import later. The point of importing 'default.i18n.dart' before you create the translations for that widget is that it will record them as missing translations, so that you don't forget to add those translations later.


 

Q: Can I do translations outside of widgets?

A: Yes, since you don't need access to context. It actually reads the current locale from I18n.locale, which is static, and all the rest is done with pure Dart code. So you can translate anything you want, from any code you want. You can also define a locale on the fly if you want to do translations to a locale different from the current one.


 

Q: By using identifier keys like howAreYou, I know that there's a localization key named howAreYou because otherwise my code wouldn't compile. There is no way to statically verify that "How are you?".i18n will do what I want it to do.

A: i18n_extension lets you decide if you want to use identifier keys like howAreYou or not. Not having to use those was one thing I was trying to achieve. I hate having to come up with these keys. I found that the developer should just type the text they want and be done with it. In other words, in i18n_extension you don't need to type a key; you may type the text itself (in your default language). So there is no need to statically verify anything. Your code will always compile when you type a String, and that exact string will be used for your default language. It will never break.


 

Q: But how can I statically verify that a string has translations? Just showing the translatable string as defined in the source code will not hide that some translations are missing?

A: You can statically verify that a string should have translations because it has .i18n attached to it. What you can't do is statically verify that those translations were actually provided for all supported languages. But this is also the case when you use older methods. With the older methods you also just know it should have translations, because it has a translation key, but the translation itself may be missing, or worse yet, outdated. With i18n_extension at least you know that the translation to the default language exists and is not outdated.


 

Q: What happens if a developer tries to call i18n on a string without translations, wouldn't that be harder to catch?

A: With i18n_extension you can generate a report with all missing translations, and you can even add those checks to tests. In other words, you can just freely modify any translatable string, and before your launch you get the reports and fix all the translations.


 

Q: There are a lot of valid usages for String that don't deal with user-facing messages. I like to use auto-complete to see what methods are available (by typing someString.), and seeing loads of unrelated extension methods in there could be annoying.

A: The translation extension is contained in your widget file. You won't have this extension in scope for your business classes, for example. So .i18n will only appear in your auto-complete inside of your widget classes, where it makes sense.


 

Q: Do I actually need one .i18n.dart (a translations file) per widget?

A: No you don't. It's suggested that you create a translation file per widget if you are doing translations by hand, but that's not a requirement. The reason I think separate files is a good idea is that sometimes internationalization is not only translations. You may need to format dates in specific ways, or make complex functions to create specific strings that depend on variables etc. So in these cases you will probably need somewhere to put this code. In any case, to make translations work all you need a Translation object which you can create in many ways, by adding maps to it using the + operator, or by adding other translation objects together using the * operator. You can create this Translation objects anywhere you want, in a single file per widget, in a single file for many widgets, or in a single file for the whole app. Also, if you are not doing translations by hand but importing strings from translation files, then you don't even need a separate file. You can just add extension Localization on String { String get i18n => localize(this, Translations("en_us") + load("file.json")); } to your own widget file.


 

Q: Won't having multiple files with extension Localization lead to people importing the wrong file and have translations missing?

A: The package records all your missing translations, and you can also easily log or throw an exception if they are missing. So you will know if you import the wrong file. You can also add this reports to your unit tests. It will let you know even if you import the right file and translations are missing in some language, and it will let you know even if you import from .arb files and translations are missing in some language.


 

Q: Are there importers for X?

A: Currently, only .PO and .JSON importers are supported out-of-the-box. Keep in mind this lib development is still new, and I hope the community will help writing more importers/exporters. We hope to have those for .arb .icu .xliff .csv and .yaml, but we're not there yet. However, since the Translations object use maps as input/output, you can use whatever file you want if you convert them to a map yourself.


 

Q: How does it report missing translations?

A: _At the moment you should just print Translations.missingKeys and Translations.missingTranslations. We'll later create a Translations.printReport() function that correlates these two pieces of information and outputs a more readable report.


 

Q: The package says it's "Non-boilerplate", but doesn't .i18n.dart contain boilerplate?

A: The only necessary boilerplate for .i18n.dart files is static var _t = Translations("...") + and String get i18n => localize(this, _t);. The rest are the translations themselves. So, yeah, it's not completely without boilerplate, but saying "Less-boilerplate" is not that catchy.

The Flutter packages I've authored:

My Medium Articles:

My article in the official Flutter documentation:

---
Marcelo Glasberg:
https://github.com/marcglasberg
https://twitter.com/glasbergmarcelo
https://stackoverflow.com/users/3411681/marcg
https://medium.com/@marcglasberg

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add i18n_extension

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):


dependencies:
  i18n_extension: ^4.1.1

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

Import it

Now in your Dart code, you can use:

import 'package:i18n_extension/i18n_extension.dart'; 

example/README.md

I18n examples

Please run main.dart in folders:

example/lib/example1

Demonstrates basic translations using a I18n widget.

There are 3 widget files that need translations:

  • main.dart
  • my_screen.dart
  • my_widget.dart

And there is one translations-file for each one:

  • main.i18n.dart
  • my_screen.i18n.dart
  • my_widget.i18n.dart

Note: We could have put all translations into a single translations-file that would be used by all widget files. It's up to you how to organize things.

Note: The translations-files in this example use strings as keys. For example:

"You clicked the button %d times:".plural(counter),

example/lib/example2

Demonstrates basic translations using a I18n widget.

There are 3 widget files that need translations:

  • main.dart
  • my_screen.dart
  • my_widget.dart

But this time we demonstrate how to use a single translations-file for all of them:

  • my.i18n.dart

Note: The translations-files in this example use identifiers as keys. For example:

 youClickedThisNumberOfTimes.plural(counter)

example/lib/example3

Demonstrates having two I18n widgets. It is NOT recommended to have two I18n widgets, at all. However, if for some reason it is inevitable, I've provided the I18n.forceRebuild() method to help you deal with it.

Download Details:

Author: marcglasberg

Source Code: https://github.com/marcglasberg/i18n_extension

#flutter #i18n 

What is GEEK

Buddha Community

Translation and Internationalization (i18n) for Flutter

Google's Flutter 1.20 stable announced with new features - Navoki

Flutter Google cross-platform UI framework has released a new version 1.20 stable.

Flutter is Google’s UI framework to make apps for Android, iOS, Web, Windows, Mac, Linux, and Fuchsia OS. Since the last 2 years, the flutter Framework has already achieved popularity among mobile developers to develop Android and iOS apps. In the last few releases, Flutter also added the support of making web applications and desktop applications.

Last month they introduced the support of the Linux desktop app that can be distributed through Canonical Snap Store(Snapcraft), this enables the developers to publish there Linux desktop app for their users and publish on Snap Store.  If you want to learn how to Publish Flutter Desktop app in Snap Store that here is the tutorial.

Flutter 1.20 Framework is built on Google’s made Dart programming language that is a cross-platform language providing native performance, new UI widgets, and other more features for the developer usage.

Here are the few key points of this release:

Performance improvements for Flutter and Dart

In this release, they have got multiple performance improvements in the Dart language itself. A new improvement is to reduce the app size in the release versions of the app. Another performance improvement is to reduce junk in the display of app animation by using the warm-up phase.

sksl_warm-up

If your app is junk information during the first run then the Skia Shading Language shader provides for pre-compilation as part of your app’s build. This can speed it up by more than 2x.

Added a better support of mouse cursors for web and desktop flutter app,. Now many widgets will show cursor on top of them or you can specify the type of supported cursor you want.

Autofill for mobile text fields

Autofill was already supported in native applications now its been added to the Flutter SDK. Now prefilled information stored by your OS can be used for autofill in the application. This feature will be available soon on the flutter web.

flutter_autofill

A new widget for interaction

InteractiveViewer is a new widget design for common interactions in your app like pan, zoom drag and drop for resizing the widget. Informations on this you can check more on this API documentation where you can try this widget on the DartPad. In this release, drag-drop has more features added like you can know precisely where the drop happened and get the position.

Updated Material Slider, RangeSlider, TimePicker, and DatePicker

In this new release, there are many pre-existing widgets that were updated to match the latest material guidelines, these updates include better interaction with Slider and RangeSliderDatePicker with support for date range and time picker with the new style.

flutter_DatePicker

New pubspec.yaml format

Other than these widget updates there is some update within the project also like in pubspec.yaml file format. If you are a flutter plugin publisher then your old pubspec.yaml  is no longer supported to publish a plugin as the older format does not specify for which platform plugin you are making. All existing plugin will continue to work with flutter apps but you should make a plugin update as soon as possible.

Preview of embedded Dart DevTools in Visual Studio Code

Visual Studio code flutter extension got an update in this release. You get a preview of new features where you can analyze that Dev tools in your coding workspace. Enable this feature in your vs code by _dart.previewEmbeddedDevTools_setting. Dart DevTools menu you can choose your favorite page embed on your code workspace.

Network tracking

The updated the Dev tools comes with the network page that enables network profiling. You can track the timings and other information like status and content type of your** network calls** within your app. You can also monitor gRPC traffic.

Generate type-safe platform channels for platform interop

Pigeon is a command-line tool that will generate types of safe platform channels without adding additional dependencies. With this instead of manually matching method strings on platform channel and serializing arguments, you can invoke native class and pass nonprimitive data objects by directly calling the Dartmethod.

There is still a long list of updates in the new version of Flutter 1.2 that we cannot cover in this blog. You can get more details you can visit the official site to know more. Also, you can subscribe to the Navoki newsletter to get updates on these features and upcoming new updates and lessons. In upcoming new versions, we might see more new features and improvements.

You can get more free Flutter tutorials you can follow these courses:

#dart #developers #flutter #app developed #dart devtools in visual studio code #firebase local emulator suite in flutter #flutter autofill #flutter date picker #flutter desktop linux app build and publish on snapcraft store #flutter pigeon #flutter range slider #flutter slider #flutter time picker #flutter tutorial #flutter widget #google flutter #linux #navoki #pubspec format #setup flutter desktop on windows

Terry  Tremblay

Terry Tremblay

1598396940

What is Flutter and why you should learn it?

Flutter is an open-source UI toolkit for mobile developers, so they can use it to build native-looking** Android and iOS** applications from the same code base for both platforms. Flutter is also working to make Flutter apps for Web, PWA (progressive Web-App) and Desktop platform (Windows,macOS,Linux).

flutter-mobile-desktop-web-embedded_min

Flutter was officially released in December 2018. Since then, it has gone a much stronger flutter community.

There has been much increase in flutter developers, flutter packages, youtube tutorials, blogs, flutter examples apps, official and private events, and more. Flutter is now on top software repos based and trending on GitHub.

Flutter meaning?

What is Flutter? this question comes to many new developer’s mind.

humming_bird_dart_flutter

Flutter means flying wings quickly, and lightly but obviously, this doesn’t apply in our SDK.

So Flutter was one of the companies that were acquired by **Google **for around $40 million. That company was based on providing gesture detection and recognition from a standard webcam. But later when the Flutter was going to release in alpha version for developer it’s name was Sky, but since Google already owned Flutter name, so they rename it to Flutter.

Where Flutter is used?

Flutter is used in many startup companies nowadays, and even some MNCs are also adopting Flutter as a mobile development framework. Many top famous companies are using their apps in Flutter. Some of them here are

Dream11

Dream11

NuBank

NuBank

Reflectly app

Reflectly app

Abbey Road Studios

Abbey Road Studios

and many more other apps. Mobile development companies also adopted Flutter as a service for their clients. Even I was one of them who developed flutter apps as a freelancer and later as an IT company for mobile apps.

Flutter as a service

#dart #flutter #uncategorized #flutter framework #flutter jobs #flutter language #flutter meaning #flutter meaning in hindi #google flutter #how does flutter work #what is flutter

Adobe XD plugin for Flutter with CodePen Tutorial

Recently Adobe XD releases a new version of the plugin that you can use to export designs directly into flutter widgets or screens. Yes, you read it right, now you can make and export your favorite design in Adobe XD and export all the design in the widget form or as a full-screen design, this can save you a lot of time required in designing.

What we will do?
I will make a simple design of a dialogue box with a card design with text over it as shown below. After you complete this exercise you can experiment with the UI. You can make your own components or import UI kits available with the Adobe XD.

#developers #flutter #adobe xd design export to flutter #adobe xd flutter code #adobe xd flutter code generator - plugin #adobe xd flutter plugin #adobe xd flutter plugin tutorial #adobe xd plugins #adobe xd to flutter #adobe xd tutorial #codepen for flutter.

Brain  Crist

Brain Crist

1602147600

Flutter App Development Trends 2020

As the new decade dawns upon us, a slew of technologies has been making a lot of noise to grab the developers’ attention. While native app development is going strong, the trade winds are now blowing towards going cross-platform.

Adobe PhoneGap, React Native, Xamarin and Ionic are all leaving no stone unturned to be the undefeated champion of cross-platform development. Still, Google’s Flutter is all set to take them all on at once.

There are a tonne of resources available online to learn about Flutter, and you can start with this step by step flutter guide.

With reduced code development time, increased time-to-market speed, near-native performance, and a bevy of advantages under its hood, Flutter is set to dominate the market this decade.

Before we take a look at trends making the Flutter race ahead in 2020, let us do a quick recap of what Flutter is, for those who have been living under a rock.

#flutter #flutter-for-mobile-app #flutter-app-development #mobile-app-development #flutter-trends #software-development #advantages-of-flutter-mobile #pros-and-cons-of-flutter

Maida  Ratke

Maida Ratke

1590832500

Themes in Flutter: Part 3

In the 1st part, we saw 15 parameters of ThemeData class. Those were brightness, visualDensity, primaryColor, primaryColorBrightness, primaryColorLight, primaryColorDark, canvasColor, ascentColor, ascentColorBrightness, scaffoldNBackgroundColor, bottomAppBarColor, cardColor, dividerColor, focusColor.
In the 2nd part, we saw 27 parameters of ThemeData class. Those were hoverColor, hightlightColor, splashColor, splashFactory, selectedRowColor, unselectedWidgetColor, disabledColor, buttonTheme, toggleButtonsTheme, buttonColor, secondaryHeaderColor, textSelectionColor, cursorColor, textSelectionHandleColor, backgroundColor, dialogBackgroundColor, indicatorColor, hintColor, errorColor, toggleableActiveColor, textTheme, primaryTextTheme, accentTextTheme, inputDecorationTheme, iconTheme, primaryIconTheme, accentIconTheme.
Let’s start with 3rd set fo ThemeData parameters.

#flutter #flutter-color #flutter-widget #flutter-theme #flutter-ui