All Projects → long1eu → Flutter_i18n

long1eu / Flutter_i18n

Licence: apache-2.0
This plugin create a binding between your translations from .arb files and your Flutter app.

Programming Languages

dart
5743 projects

Projects that are alternatives of or similar to Flutter i18n

getx-snippets-intelliJ
An extension to accelerate the process of developing applications with flutter, aimed at everyone using the GetX package.
Stars: ✭ 52 (-79.61%)
Mutual labels:  intellij-plugin, flutter-plugin, flutter-apps
flutter-app
Full Feature Todos Flutter Mobile app with fireStore integration.
Stars: ✭ 138 (-45.88%)
Mutual labels:  flutter-plugin, flutter-apps
getwidget-docs
Get Widgets UI library docs.
Stars: ✭ 17 (-93.33%)
Mutual labels:  flutter-plugin, flutter-apps
liquid button
Liquify your buttons, web demo at website
Stars: ✭ 18 (-92.94%)
Mutual labels:  flutter-plugin, flutter-apps
Flutterexampleapps
[Example APPS] Basic Flutter apps, for flutter devs.
Stars: ✭ 15,950 (+6154.9%)
Mutual labels:  flutter-apps, flutter-plugin
flutter bolg manage
Flutter实战项目,采用Getx框架管理,遵循Material design设计风格,适合您实战参考或练手
Stars: ✭ 373 (+46.27%)
Mutual labels:  flutter-plugin, flutter-apps
android-studio-plugin
Integrate your Android project with Crowdin
Stars: ✭ 52 (-79.61%)
Mutual labels:  i18n, intellij-plugin
Awesome Flutter
An awesome list that curates the best Flutter libraries, tools, tutorials, articles and more.
Stars: ✭ 38,582 (+15030.2%)
Mutual labels:  flutter-apps, flutter-plugin
Web Vuw
A Web View for flutter
Stars: ✭ 40 (-84.31%)
Mutual labels:  flutter-plugin, flutter-apps
nepali date picker
Material Style Date Picker with Bikram Sambat(Nepali) Calendar Support. Supports both Android and ios.
Stars: ✭ 30 (-88.24%)
Mutual labels:  flutter-plugin, flutter-apps
flutter-tunein
Dynamically themed Music Player built with flutter
Stars: ✭ 108 (-57.65%)
Mutual labels:  flutter-plugin, flutter-apps
Flutter Credit Card Input Form
Flutter Credit Card Input form
Stars: ✭ 201 (-21.18%)
Mutual labels:  flutter-apps, flutter-plugin
Flutter Apps Collection
This is a repository of a collection of apps made in flutter
Stars: ✭ 98 (-61.57%)
Mutual labels:  flutter-apps, flutter-plugin
A-Complete-Guide-To-Flutter
This repo contains all the small snippets related to Flutter Apps. Most of the projects/apps are deployed on Flutter Web using GitHub Actions CI Pipeline.
Stars: ✭ 70 (-72.55%)
Mutual labels:  flutter-plugin, flutter-apps
Math Metrix
This is Math-Puzzle game made in flutter and available on Playstore & AppStore
Stars: ✭ 48 (-81.18%)
Mutual labels:  flutter-apps, flutter-plugin
Motion-Tab-Bar
A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.
Stars: ✭ 237 (-7.06%)
Mutual labels:  flutter-plugin, flutter-apps
Flutter thrio
flutter_thrio makes it easy and fast to add flutter to existing mobile applications, and provide a simple and consistent navigator APIs.
Stars: ✭ 717 (+181.18%)
Mutual labels:  flutter-apps, flutter-plugin
Flutter Cinema
Learn to create flutter app with BLoC Architecture
Stars: ✭ 26 (-89.8%)
Mutual labels:  flutter-apps, flutter-plugin
swipedetector
A Flutter package to detect up, down, left, right swipes.
Stars: ✭ 34 (-86.67%)
Mutual labels:  flutter-plugin, flutter-apps
Flutter-Apps
🌀 This is mainly focus on a complete application for production
Stars: ✭ 18 (-92.94%)
Mutual labels:  flutter-plugin, flutter-apps

PROJECT MAINTENANCE PAUSED

This project is no longer maintained due to the lack of time and availability. I'm a developer to and I know how frustrating can be when a tool I use no is no longer available or doesn't work any more. I'm sorry for the pain I've caused. :( Still in this repo the is a CLI tool that can work without the help of the IDE, and uses pure Dart to generate files in the same format. https://github.com/long1eu/flutter_i18n/tree/master/flutter_l10n Please give it a try, maybe it can ease your pain.

As of today I requested Intellij to remove the plugin from the market. Thanks for all the support.

Synopsis

This plugin helps you internationalize you Flutter app by generating the needed boiler plate code. You just add and organize strings in files that are contained in the /res/values folder. This plugin is based on the Internationalizing Flutter Apps tutorial and on the Material Library Localizations package. Much of the instructions are taken from there.

Usage

1. Setup you App

Setup your localizationsDelegates and your supportedLocales which allows the access to the internationalized strings.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      onGenerateTitle: (BuildContext context) => S.of(context).app_name,
      localizationsDelegates: const <LocalizationsDelegate<WidgetsLocalizations>>[
            S.delegate,
            // You need to add them if you are using the material library.
            // The material components usses this delegates to provide default 
            // localization      
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,               
      ],
      supportedLocales: S.delegate.supportedLocales,
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

Optionally, you can provide a fallback Locale for the unsupported languages in case the user changes the device language to an unsupported language. The default resolution is:

  1. The first supported locale with the same Locale.languageCode.
  2. The first supported locale.

If you want to change the last step and to provided a default locale instead of choosing the first one in you supported list, you can specify that as fallows:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      localizationsDelegates: [
            S.delegate,
            // You need to add them if you are using the material library.
            // The material components usses this delegates to provide default 
            // localization 
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
      ],
      supportedLocales: S.delegate.supportedLocales,

      localeResolutionCallback:
          S.delegate.resolution(fallback: const Locale('en', '')),
      // this is equivalent to having withCountry: false, as in the next call:
      localeResolutionCallback:
          S.delegate.resolution(fallback: const Locale('en', ''), withCountry: false),

      // - OR -

      localeListResolutionCallback:
          S.delegate.listResolution(fallback: const Locale('en', '')),    
      // this is equivalent to having withCountry: false, as in the next call:
      localeListResolutionCallback:
          S.delegate.listResolution(fallback: const Locale('en', ''), withCountry: false),

      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

2. Setup the arb files.

ARB files extension stands for Application Resource Bundle which is used by the Dart intl package. ARB files are supported by the Google Translators Toolkit, thus supported by Google.

Flutter internalization only depends on a small subset of the ARB format. Each .arb file contains a single JSON table that maps from resource IDs to localized values. Filenames contain the locale that the values have been translated for. For example, material_de.arb contains German translations, and material_ar.arb contains Arabic translations. Files that contain regional translations have names that include the locale's regional suffix. For example, material_en_GB.arb contains additional English translations that are specific to Great Britain.

The first English file is generated for you(/res/values/strings_en.arb). Every arb file depends on this one. If you have a string in the German arb file(/res/values/strings_de.arb) that has an ID which is not found in the English file, it would not be listed. So you must be sure to first have the strings in the English file and then add other translations.

To add a new arb file right click on values folder and select New -> Arb File. Then pick your language from the list, and region if necessary.

1. Referencing the values

The ARB table's keys, called resource IDs, are valid Dart variable names. They correspond to methods from the S class. For example:

Widget build(BuildContext context) {
  return new FlatButton(
    child: new Text(
      S.of(context).cancelButtonLabel,
    ),
  );
}

2. Parameterized strings

Some strings may contain $variable tokens which are replaced with your values. For example:

{   
    "aboutListTileTitle": "About $applicationName"  
}

The value for this resource ID is retrieved with a parameterized method instead of a simple getter:

S.of(context).aboutListTileTitle(yourAppTitle)

3. Plurals

Plural translations can be provided for several quantities: 0, 1, 2, "few", "many", "other". The variations are identified by a resource ID suffix which must be one of "Zero", "One", "Two", "Few", "Many", "Other" (case insensitive). The "Other" variation is used when none of the other quantities apply. All plural resources must include a resource with the "Other" suffix. For example the English translations ('material_en.arb') for selectedRowCountTitle in the Material Library Localizations are:

{
    "selectedRowCountTitleZero": "No items selected",
    "selectedRowCountTitleMany": "to many items", //not actual real
    "selectedRowCountTitleOne": "1 item selected",
    "selectedRowCountTitleOther": "$selectedRowCount items selected",</pre>
}

Then, we can reference these strings as follows:

S.of(context).selectedRowCountTitle("many")

or

S.of(context).selectedRowCountTitle("1")

or

S.of(context).selectedRowCountTitle("$selectedRowCount")

3. Turning off the plugin per project.

With the release of v1.1.0 of the plugin, it is possible to turn on or off the plugin per project by adding a new top-level configuration option in your project's pubspec.yaml file: flutter_i18n

The plugin will be turned off by default for Dart-only projects, and on by default for Flutter projects. To change this setting, however, you have two options under the top-level flutter_i18n configuration:

enable-flutter-i18n: true / false

To activate the plugin for a Flutter project. The default setting is true.

enable-for-dart: true / false

To activate the plugin for a Dart-only project. The default setting is false.

NOTES:

  • The plugin also supports ${variable} notation. Use this when the parser does not catch the parameters properly. For example:

    {"tabLabel": "탭 $tabCount개 중 $tabIndex번째"}
    

    generates

    String tabLabel(String tabCount, String tabIndex번째) => "탭 $tabCount개 중 $tabIndex번째";
    

    Which contains invalid Dart fields. In this case you should use

    {"tabLabel": "탭 ${tabCount}개 중 ${tabIndex}번째"}
    
  • Also you can escape the $ sign with \

    {"checkout_message": "You have to pay \$$price"}
    

Issues

There are some performance improvements and bug fixes that this plugin could use, so feel free to PR.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].