flutter_translator 0.0.3 copy "flutter_translator: ^0.0.3" to clipboard
flutter_translator: ^0.0.3 copied to clipboard

discontinuedreplaced by: flutter_localization
outdated

Flutter Translator is a package use for in-app localization with json file. More easier and faster to implement. This package is inspired by the flutter_localizations itself.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter_translator/translator_generator.dart';

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

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

class _MyAppState extends State<MyApp> {
  final _translator = TranslatorGenerator.instance;

  @override
  void initState() {
    _translator.init(
      languageCodes: ['en', 'kh', 'ja'],
      initLanguageCode: null,
    );
    _translator.onTranslatedLanguage = _onTranslatedLanguage;
    super.initState();
  }

  void _onTranslatedLanguage(Locale locale) {
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      supportedLocales: _translator.supportedLocales,
      localizationsDelegates: _translator.localizationsDelegates,
      home: SettingsScreen(),
    );
  }
}

class SettingsScreen extends StatefulWidget {
  @override
  _SettingsScreenState createState() => _SettingsScreenState();
}

class _SettingsScreenState extends State<SettingsScreen> {
  final _translator = TranslatorGenerator.instance;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(_translator.getString(context, 'title'))),
      body: Container(
        padding: const EdgeInsets.all(16.0),
        child: Center(
          child: Row(
            children: [
              Expanded(
                child: RaisedButton(
                  child: Text('English'),
                  onPressed: () {
                    _translator.translate('en');
                  },
                ),
              ),
              Expanded(
                child: RaisedButton(
                  child: Text('Khmer'),
                  onPressed: () {
                    _translator.translate('kh');
                  },
                ),
              ),
              Expanded(
                child: RaisedButton(
                  child: Text('Japanese'),
                  onPressed: () {
                    _translator.translate('ja');
                  },
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
12
likes
0
pub points
63%
popularity

Publisher

unverified uploader

Flutter Translator is a package use for in-app localization with json file. More easier and faster to implement. This package is inspired by the flutter_localizations itself.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_localizations

More

Packages that depend on flutter_translator