internationalization 2.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

internationalization #

A project to easily implement internationalization on flutter projects

Configure Internationalization #

Create a yaml file named internationalization then do the configurations like this:

path: ./assets/strings
default_locale:
  language: en
  country: US
locales:
  - locale:
      language: pt
  - locale:
      language: en
      country: US
  • path -> where JSON files (strings) were placed
  • default_locale -> default strings
  • locales -> Array of locales

Now import internationalization package on main.dart.

import 'package:internationalization/internationalization.dart';

Make void main() async then load internationalization configurations

void main() async {
  await Internationalization.loadConfigurations();
  runApp(InternationalizationExampleApp());
}

Pass the delegates to localizationsDelegates.

@override
Widget build(BuildContext context) {
    return MaterialApp(
        supportedLocales: suportedLocales,
        localizationsDelegates: [
            Internationalization.delegate,
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
        ],
    );
}

In pubspec.yaml put the path that you've passed to InternationalizationDelegate and the configuration file

flutter:
  assets:
    - ./assets/strings/
    - ./internationalization.yaml

Usage #

Strings.of(context).valueOf("key") //To get a simple string
Strings.of(context).valueOf("key", args: ["A", "B", "C"]) //To get an interpoled string
Strings.of(context).pluralOf("key", 0) //To get a plural string
Strings.of(context).pluralOf("key", 0, args: ["A", "B", "C"]) //To get a plural interpoled string
Strings.of(context).valueOf("key", args: ["A", "B", "C"], namedArgs: {"named_arg_key": "Named arg"}) //To get an interpoled name string

JSON file #

Crete JSON files with locale language code and country code. Ex.: pt.json, en_US.json, etc... Note: create JSON files inside folder you passed to InternationalizationDelegate

{
    "simple_string": "Simple string value",
    "interpolation_string": "Interpoleted {0} string {1}",
    "simple_plurals" : {
        "zero": "No information",
        "one": "A item",
        "other": "Many itens"
    },
    "interpolation_plurals": {
        "zero": "No information {0} with {1}",
        "one": "A item {0} with {1}",
        "other": "Many itens {0} with {1}"
    },
    "interpolation_string_with_named_args": "Interpoleted {0} string with ::named_arg_key::"
}

[2.0.0] (October 1, 2019)

  • Configurations via yaml file

[1.2.0] (Agust 16, 2019)

  • Removed need to pass country code

[1.1.0+1] (Agust 16, 2019)

  • README example for named interpolation

[1.1.0] (Agust 16, 2019)

  • Added suport for named interpolation

[1.0.1] (Agust 6, 2019)

  • Null safety for locales

[1.0.0+1] (July 27, 2019)

  • Refactor code

[1.0.0] (July 25, 2019)

  • Initial release

example/README.md

internationalization_example #

A example project for internationalization

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

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


dependencies:
  internationalization: ^2.0.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:internationalization/internationalization.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
66
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

We analyzed this package on Oct 18, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

10 out of 10 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.

Format lib/internationalization.dart.

Run flutter format to format lib/internationalization.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
flutter_localizations 0.0.0
yaml ^2.1.16 2.2.0
Transitive dependencies
charcode 1.1.2
collection 1.14.11 1.14.12
intl 0.15.8 0.16.0
meta 1.1.7
path 1.6.4
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8