auto_localization 0.1.9 copy "auto_localization: ^0.1.9" to clipboard
auto_localization: ^0.1.9 copied to clipboard

outdated

A way to automatically translate all your app to the phone Localization.

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.

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"); //--> Result in "La crema irlandese di Bailey" which is wrong
translateText("Bailey's irish cream", language: "it", target: "cocktail"); //--> 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")

Wrap your Text widget with this:

TextLocal(Text("Plugin example app"))

If you need to create your own Translated widget you could act like this

class TextLocal extends StatefulWidget {
  final Text text;
  final String target;
  final String lang;

  TextLocal(this.text,{this.lang,this.target});

  @override
  _TextLocalState createState() => _TextLocalState();
}

class _TextLocalState extends State<TextLocal> {

  String trans;

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

  String cachedString="";
  translate() async {
    cachedString=widget.text.data;
    trans=await translateText(widget.text.data, language: widget.lang, target: widget.target);
    if(mounted){
      setState(() {
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    if(cachedString!=widget.text.data){
      translate();
    }
    return Text(
      trans??widget.text.data,
      strutStyle: widget.text.strutStyle,
      style: widget.text.style,
      softWrap: widget.text.softWrap,
      semanticsLabel: widget.text.semanticsLabel,
      textScaleFactor: widget.text.textScaleFactor,
      maxLines: widget.text.maxLines,
      textWidthBasis: widget.text.textWidthBasis,
      textDirection: widget.text.textDirection,
      overflow: widget.text.overflow,
      locale: widget.text.locale,
      textAlign: widget.text.textAlign,
      key: widget.text.key,
    );
  }

}

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

String x= await translateText("hello");
14
likes
0
pub points
71%
popularity

Publisher

verified publishersipio.it

A way to automatically translate all your app to the phone Localization.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

auto_size_text, devicelocale, flutter, sqflite, synchronized, translator

More

Packages that depend on auto_localization