firelang 1.0.2
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'slib/
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:
- Fork the repo.
- Create a feature branch.
- 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