firelang 1.0.2 copy "firelang: ^1.0.2" to clipboard
firelang: ^1.0.2 copied to clipboard

Automates Firebase Remote Config multi-language support in Flutter apps.

πŸš€ FireLang - Firebase Lang Config #

FireLang is an open-source Dart/Flutter package that automates multi-language translations for Firebase Remote Config.

πŸ”Ή It reads translation files from your project's config/ directory and generates:

  • βœ… RemoteConfig JSON (remoteconfig.template.json) for Firebase.
  • βœ… Dart Localization Class (lib/lang.dart) for Flutter apps.

πŸ“Œ Features #

  • πŸ”Ή Automates Firebase Remote Config multi-language setup.
  • πŸ”Ή Ensures translation consistency across all locales.
  • πŸ”Ή Supports any number of languages (JSON-based translations).
  • πŸ”Ή Generates a Dart localization class (Lang) for use in Flutter.
  • πŸ”Ή Validates missing or extra keys to prevent translation mismatches.
  • πŸ”Ή Supports deployment as a dev dependency for easy use.

πŸš€ Installation #

1️⃣ Install from pub.flutter-io.cn #

Once the package is published, you can add it to your pubspec.yaml:

dev_dependencies:
  firelang: ^1.0.2

Then run:

dart pub get

2️⃣ Setup Translation Files (Inside Your Project) #

Inside your Flutter/Dart project root, create a config/ directory:

my_flutter_project/
│── config/
β”‚   β”œβ”€β”€ dp/
β”‚   β”‚   β”œβ”€β”€ default.json  <-- Default translations (required)
β”‚   β”‚   β”œβ”€β”€ en.json  <-- English translations (required)
β”‚   β”‚   β”œβ”€β”€ es.json  <-- Spanish translations (optional)
β”‚   β”‚   β”œβ”€β”€ fr.json  <-- French translations (optional)
│── lib/
β”‚   β”œβ”€β”€ main.dart
β”‚   β”œβ”€β”€ lang.dart  <-- πŸ”₯ Auto-generated localization class
│── pubspec.yaml

3️⃣ Translation JSON Structure #

Each JSON file inside config/ should have the same keys across all languages.

βœ… Example: config/dp/en.json

{
  "welcome": "Welcome",
  "logout": "Log Out",
  "error": "Something went wrong"
}

βœ… Example: config/dp/es.json

{
  "welcome": "Bienvenido",
  "logout": "Cerrar sesiΓ³n",
  "error": "Algo saliΓ³ mal"
}

🚨 Every translation file must have the same keys.
If any language is missing a key, the script will throw an error.


⚑️ Usage #

1️⃣ Build & Deploy #

Run this command inside your Flutter project root:

dart run firelang

What This Command Does #

  • βœ… Reads translations from your config/ folder.
  • βœ… Generates remoteconfig.template.json in your project root.
  • βœ… Deploys Firebase Remote Config using firebase deploy.
  • βœ… Creates lib/lang.dart in your project's lib/ folder.

πŸ“Œ How to Use lang.dart in Flutter #

Your Dart localization class (Lang) will be auto-generated inside your lib/lang.dart.

1️⃣ Add Lang.delegate to MaterialApp #

Inside your main.dart, add Lang.delegate:

import 'package:flutter/material.dart';
import 'package:firelang/lang.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Lang().init(); // Initialize translations
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        Lang.delegate, 
      ],
      home: HomeScreen(),
    );
  }
}

2️⃣ Access Translations in Your App #

Lang.of(context).welcome   // Gets "Welcome" in English or "Bienvenido" in Spanish
Lang.of(context).logout    // Gets "Log Out" or "Cerrar sesiΓ³n"

3️⃣ Manually Set Language #

If you want to force a specific language, call:

Lang.setLanguage('es');  // Switch to Spanish
Lang.setLanguage('en');  // Switch back to English
Lang.setLanguage('');    // Reset to device default

πŸ”§ Firebase Deployment #

After building your config, deploy it manually using:

firebase deploy --only remoteconfig

πŸš€ This will update Firebase Remote Config with your latest translations.


❓ FAQ #

Where does lang.dart go? #

βœ… It is generated in your project's lib/ directory.

Where does remoteconfig.template.json go? #

βœ… It is generated in your project's root directory.

What if a translation file is missing a key? #

🚨 The script will throw an error and show which keys are missing.

Can I add more languages later? #

Yes! Just add new .json files inside config/dp/, then run the build command again:

dart run firelang

πŸ‘¨β€πŸ’» Contributing #

We welcome contributions! Feel free to:

  1. Fork the repo.
  2. Create a feature branch.
  3. Submit a pull request.

πŸ“œ License #

This project is licensed under the MIT License.


πŸš€ Final Thoughts #

🎯 FireLang simplifies multi-language support for Firebase Remote Config and Flutter.
πŸ”₯ One command to sync translations across Dart, Flutter, and Firebase.


✨ Star this repo if you found it useful! πŸš€
πŸ“Œ GitHub Repo: https://github.com/alltruevalue/firelang

1
likes
140
points
27
downloads

Publisher

verified publisherdpinvision.com

Weekly Downloads

Automates Firebase Remote Config multi-language support in Flutter apps.

Repository (GitHub)
View/report issues

Topics

#firebase #flutter #localization #remote-config

Documentation

API reference

License

unknown (license)

Dependencies

flutter

More

Packages that depend on firelang