my_lang 0.0.1 copy "my_lang: ^0.0.1" to clipboard
my_lang: ^0.0.1 copied to clipboard

retracted

A library that provides flexible and easy-to-use localization support for Flutter applications.

my_lang #

Introduction #

my_lang is a library that provides flexible and easy-to-use localization support for Flutter applications.

Features #

  • Multi-language support using JSON files.
  • Easy to integrate and use.
  • Dynamic language switching in the app.
  • Automatically reads JSON files and generates Dart files without manually entering each key.

Installation #

Add the following to your pubspec.yaml:

my_lang: ^latest_version

flutter:
  assets:
    - assets/i18n/

JSON Language File Structure #

Create JSON files inside the assets/i18n/ directory:

en.json

{
  "welcomeBack": "Welcome Back",
  "welcomeBackNameApp": "Welcome @nameUser Back @nameApp"
}

vi.json

{
  "welcomeBack": "Chào mừng trở lại",
  "welcomeBackNameApp": "Chào mừng @nameUser trở lại @nameApp"
}

Initializing the Library #

import 'package:my_lang/my_lang.dart';
import 'package:flutter/widgets.dart';

MyLang myLang = MyLang();

const listLocale = [
  Locale('en'),
  Locale('vi'),
];

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await myLang.setUp(listLocale: listLocale);
  runApp(MyApp());
}

Creating the interpreter.dart File #

Create the interpreter.dart file containing the OurLang class:

import 'package:my_lang/my_lang.dart';

class OurLang extends MyLang {
  static String get welcomeBack => MyLang.translate('welcomeBack');
  static String? welcomeBackNameApp(String nameUser, String nameApp) =>
      MyLang.translate('welcomeBackNameApp', params: {
        'nameUser': nameUser,
        'nameApp': nameApp,
      });
}

Usage #

print(OurLang.welcomeBack); // "Welcome Back" or "Chào mừng trở lại"
print(OurLang.welcomeBackNameApp("John", "MyApp"));

Changing Language in the App #

myLang.loadFileJson(locale: myLang.locale.languageCode == 'en'
? const Locale("vi")
    : const Locale("en"));

Generating OurLang Automatically #

Run the following command to automatically generate interpreter.dart:

dart pub global activate my_lang
dart run my_lang -i assets/i18n/en.json -o lib/interpreter.dart

💡 Tip: Bạn có thể nhanh chóng sao chép đường dẫn tệp bằng phím tắt:

  • MacBook: Command (⌘) + Option (⌥) + C
  • Windows: Ctrl + Shift + C

Contribution #

If you have any suggestions or find any issues, feel free to open an issue or submit a pull request on GitHub.

Developer Team: #

Any comments please contact us ThaoDoan and DucNguyen.

Buy Me A Coffee

Support Me on Ko-fi

1
likes
0
points
18
downloads

Publisher

verified publisherwongcoupon.com

Weekly Downloads

A library that provides flexible and easy-to-use localization support for Flutter applications.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, intl, shared_preferences

More

Packages that depend on my_lang