pq_localization 1.2.4

PQ_Localization #

Simple Package to handle localization for flutter

Installation #

add this line to your pubspec.yaml

pq_localization: any

Usage #

import 'package:pq_localization/pq_localization.dart';

  LocalizedMaterialAppBuilder(
      # This method must return material app
      builder: (Locale locale, LocalizationsDelegate delegate) {
        return MaterialApp(
          locale: locale,
          localizationsDelegates: [
            //...other delegates
            delegate,
          ],
        );
      },
      # default locale that will be used if no locales saved in shared prefrences
      defualtLocale: Locale("ar"),

      getResources: (Locale locale) async {
       # this method return Furure so you can get your resources on any way.
       # json files or internet or any thing its your choice
        if (locale.countryCode == "ar")
          return {"app_name": "إسم التطبيق"};
        else
          return {"app_name": "app name"};
      },
      # What ever locales you want
      # Note that this property is not mapped to default one of material apps
      # These locales are to define which locales will be used for our delegate
      supportedLocales: <String>["ar","en"],
    );

now to access the localizer you cand do this

PQLocalization.of(context).translate("Key");
PQLocalization.of(context).translateMany(["Key1","key2"]);
PQLocalization.of(context).translatePattern(RegExp("^.+$"));
PQLocalization.of(context).translateManyPattern([RegExp("^[a-z]+$"),RegExp("^[0-9]+$")]);

# The for methods above have an optional parameter called args
# This parameter replaceing the key with its value in the translated string
## #example
# You passed {"(0)":"Mohamed"} in args parameter
# The  meessage in your resources is "Hello (0) welcome to our app"
# The translated message will be "Hello Mohamed welcome to our app"

or you can use this #

LocalizedWidgetBuilder(
      builder: (PQLocalization localizer) {
        Text(localizer.translate("title"));
      },
    );

I think you now need to change your locale so you can do like that

        LocaleSwitcher(
                          builder: (LocaleController controller) {
                            return Row(
                              mainAxisSize: MainAxisSize.min,
                              children: <Widget>[
                                ChoiceChip(
                                  onSelected: (bool v) {
                                    controller.setLocale(Locale("ar"));
                                  },
                                  label: Text("العربية"),
                                  selected: controller.localeCode == "ar",
                                ),
                                SizedBox(
                                  width: 20,
                                ),
                                ChoiceChip(
                                  onSelected: (bool v) {
                                    controller.setLocale(Locale("en"));
                                  },
                                  label: Text("English"),
                                  selected: controller.localeCode == "en",
                                ),
                              ],
                            );
                          },
                        )

Note #

You must use the defualt delgates like as this package will translate only your strings https://flutter.dev/docs/development/accessibility-and-localization/internationalization

[1.2.4]

  • add on localeChanged to LocalizedWidgetBuilder
  • remove mixin

[1.2.3]

  • Rebuild app after fading out

[1.2.1]

  • allow animating app while switching locale

[1.2.0]

  • add translatePattern
  • add translateManyPattern
  • add translateMany
  • update read me

[1.1.0]

  • Add example
  • Add LocaleController
  • Fix Names
  • Edit read me

[1.0.0] - 23/12/2019

  • initial release.

example/README.md

example #

A new Flutter project.

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:
  pq_localization: ^1.2.4

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

We analyzed this package on Feb 12, 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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.2.2 <3.0.0
flutter 0.0.0
shared_preferences ^0.5.6 0.5.6+1
Transitive dependencies
collection 1.14.11 1.14.12
flutter_web_plugins 0.0.0
meta 1.1.8
shared_preferences_macos 0.0.1+4
shared_preferences_platform_interface 1.0.1
shared_preferences_web 0.1.2+3
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test