auto_localization 1.1.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 69

auto_localization #

Flutter package to dynamically translate your app.

This plugin will AUTOMATICALLY detect the app Localization and translate the text.

HOW IT WORKS #

So the point was to find a way to convincely translate text in all the languages. To do that we create this system who seam to works really well. It Uses Google Translate

There is even a cache system to make it faster.

Normally our translation is composed by three part text | The text to translate

language | The end language of the text (if null will be taken the default of the device)

target | The argument of the translation (We added this because in certain circumstances translation were not accurate, i.e.

translateText("Bailey's irish cream", language: "it", alwaysTranslate: true) //--> Result in "La crema irlandese di Bailey" which is wrong
translateText("Bailey's irish cream", language: "it", target: "cocktail", alwaysTranslate: true) //--> Result in "Bailey's irish cream" which is correct

)

HOW TO USE #

Set base language into your main to not translate the text when the language is the same to which you write your app:

BaseLanguage().setBaseLanguage("en")

When you create an element you can set alwaysTranslate = TRUE and it will be translated event if the app language and device language matches, it's used to translate dynamic text, like something written by a user.

translateText("Bailey's irish cream", language: "it", target: "cocktail", alwaysTranslate: true)

The old version is replaced by this. You have to use our TranslateBuilder to make a translation, it gives you the translated String through a builder, it works with List so you can translate TextSpan.

TranslateBuilder(["Plugin example app"],(stringList, isTranslated){
            return Text(stringList[0]);
},)
TranslateBuilder(['hello auto', 'localization is','Running on: $_platformVersion\n'],(stringList, isTranslated){
            return Text.rich(TextSpan(
              children: [
                TextSpan(text: stringList[0]+' '),
                TextSpan(text: stringList[1]+' '),
                TextSpan(text: stringList[2]),

              ]
            ));
})

Convert your String with this (Need to be async):

String x= await translateText("hello");

1.1.5 #

  • Created a system to TARGET the translation
  • Optimized SQL query
  • Added base language
  • Fixed bug who stuck the text
  • Fixed some bug
  • Removed support for AutoSizeText

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:auto_localization/auto_localization.dart';

void main(){
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.


    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: TranslateBuilder(["Plugin example app"],(stringList, isTranslated){
            return Text(stringList[0]);
          },),
        ),
        body: Center(
          child: TranslateBuilder(['hello auto', 'localization is','Running on: $_platformVersion\n'],(stringList, isTranslated){
            return Text.rich(TextSpan(
                children: [
                  TextSpan(text: stringList[0]+' '),
                  TextSpan(text: stringList[1]+' '),
                  TextSpan(text: stringList[2]),

                ]
            ));
          }),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  auto_localization: ^1.1.5

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

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/auto_localization.dart.

Run flutter format to format lib/auto_localization.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
sqflite ^1.3.0 1.3.0
synchronized ^2.2.0 2.2.0
translator ^0.1.4 0.1.4
Transitive dependencies
async 2.4.1
charcode 1.1.3
collection 1.14.11 1.14.12
http 0.12.0+4
http_parser 3.1.4
meta 1.1.8
path 1.6.4
pedantic 1.9.0
sky_engine 0.0.99
source_span 1.7.0
sqflite_common 1.0.0+1
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test