trans_intl 1.0.0 copy "trans_intl: ^1.0.0" to clipboard
trans_intl: ^1.0.0 copied to clipboard

Lightweight international text translation solution plug-in.

example/lib/main.dart

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

void main() {
  I18nManager.init(trans: TranslationsService(), current: LangType.CN);
  runApp(const MyApp());
}

class Trans {
  static const String hello = 'Hello World';
}

class Ids {
  static const String hello = "hello";
}

TranslationMap trans = {
  Ids.hello: {
    LangType.EN: "Hello",
    LangType.CN: "你好",
    LangType.ES: "Hola",
    LangType.FR: "Bonjour",
    LangType.DE: "Hallo"
  },
};

class TranslationsService extends Translations {
  @override
  TranslationMap get keys => trans;
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  Future<void> _changeLan(LangType type) async {
    await I18nManager.changeLanguage(type);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text(Trans.hello.intl),
        ),
        body: Center(
          child: Column(
            children: [
              Text(Trans.hello.intl),
              RawMaterialButton(
                onPressed: () => _changeLan(LangType.EN),
                child: Text('EN'),
                fillColor: Colors.blue,
              ),
              RawMaterialButton(
                onPressed: () => _changeLan(LangType.CN),
                child: Text('CN'),
                fillColor: Colors.blue,
              ),
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
140
points
2
downloads

Publisher

unverified uploader

Weekly Downloads

Lightweight international text translation solution plug-in.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, shared_preferences

More

Packages that depend on trans_intl

Packages that implement trans_intl