multilingo 1.1.1
multilingo: ^1.1.1 copied to clipboard
Automatic localization package for Flutter with CLI tool for generating translations using Free Translate API. Features type-safe keys, runtime locale switching, and beautiful terminal UI.
๐ Multilingo ๐
๐ Supported Languages #
Multilingo supports 13+ languages covering over 5 billion speakers worldwide:
| Language | Native Name | Code |
|---|---|---|
| ๐ธ๐ฆ Arabic | ุงูุนุฑุจูุฉ | ar |
| ๐ฉ๐ช German | Deutsch | de |
| ๐ซ๐ท French | Franรงais | fr |
| ๐ช๐ธ Spanish | Espaรฑol | es |
| ๐ฎ๐น Italian | Italiano | it |
| ๐ต๐น Portuguese | Portuguรชs | pt |
| ๐ท๐บ Russian | ะ ัััะบะธะน | ru |
| ๐ฏ๐ต Japanese | ๆฅๆฌ่ช | ja |
| ๐ฐ๐ท Korean | ํ๊ตญ์ด | ko |
| ๐จ๐ณ Chinese (Simplified) | ็ฎไฝไธญๆ | zh-CN |
| ๐น๐ผ Chinese (Traditional) | ็น้ซไธญๆ | zh-TW |
| ๐ฎ๐ณ Hindi | เคนเคฟเคจเฅเคฆเฅ | hi |
| ๐น๐ท Turkish | Tรผrkรงe | tr |
| ๐ณ๐ฑ Dutch | Nederlands | nl |
| ๐ต๐ฑ Polish | Polski | pl |
And many more to be added soon
๐ฆ Installation #
Add multilingo to your pubspec.yaml:
dependencies:
multilingo: ^1.1.0
flutter_localizations:
sdk: flutter
Install dependencies:
flutter pub get
๐ Quick Start (3 Steps) #
Step 1: Create English Translations #
Create assets/l10n/en.json with your app's text:
{
"app_name": "My Awesome App",
"welcome": "Welcome!",
"greeting": "Hello, {name}!",
"items_count": "{count} items found",
"login_button": "Login",
"logout": "Logout"
}
Add to pubspec.yaml:
flutter:
assets:
- assets/l10n/
Step 2: Generate Translations #
Run the interactive CLI:
dart run multilingo:generate
What happens?
- โ
Reads your
en.jsonfile - ๐ฏ Interactive language selection
- ๐ Generates translations (e.g.,
ar.json,fr.json,es.json) - ๐ Creates
lib/locale_keys.dartwith type-safe keys
That's it! ๐
Step 3: Use in Your App #
Setup MaterialApp:
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:multilingo/multilingo.dart';
import 'locale_keys.dart'; // Auto-generated!
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// 1. Create a global navigator key
final navigatorKey = GlobalKey<NavigatorState>();
// 2. Register it with Multilingo
Multilingo.setNavigatorKey(navigatorKey);
return MaterialApp(
title: 'Multilingo Demo',
// 3. Pass it to MaterialApp
navigatorKey: navigatorKey,
// Add localization delegates
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
// Specify supported locales
supportedLocales: const [
Locale('en'), // English
Locale('ar'), // Arabic
Locale('fr'), // French
Locale('es'), // Spanish
Locale('de'), // German
],
home: const HomePage(),
);
}
}
Use Type-Safe Keys (No Context Needed!):
import 'package:multilingo/multilingo.dart';
import 'locale_keys.dart'; // Auto-generated!
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(LocaleKeys.appName), // Simple!
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(LocaleKeys.welcome),
Text(LocaleKeys.greeting),
ElevatedButton(
onPressed: () {},
child: Text(LocaleKeys.loginButton),
),
],
),
),
);
}
}
Placeholders & Dynamic Text #
Your en.json:
{
"greeting": "Hello, {name}!",
"items_count": "{count} items in cart"
}
Usage:
// With LocaleKeys (type-safe)
Text(LocaleKeys.greeting.replaceAll('{name}', 'John'))
Text(LocaleKeys.itemsCount.replaceAll('{count}', '5'))
// Or using the old way with string keys
Text('greeting'.tr().replaceAll('{name}', 'John'))
๐ API Reference #
LocaleKeys (Auto-Generated) #
Type-safe constants generated from your en.json:
class LocaleKeys {
static String get appName => 'app_name'.tr();
static String get welcome => 'welcome'.tr();
static String get greeting => 'greeting'.tr();
// ... all your keys
}
Usage:
// Use directly (recommended)
Text(LocaleKeys.appName)
// Or use string keys directly
Text('app_name'.tr())
๐ง Troubleshooting #
Q: Translation failed with timeout error?
- A: The free API may be rate-limited. Wait a moment and try again. The package has automatic retry logic.
Q: Some translations look wrong?
- A: Auto-translation is good but not perfect. Review and edit generated JSON files manually for production apps.
Q: Can I edit generated translations?
- A: Yes! Edit the generated
ar.json,fr.json, etc. files directly. Re-running the CLI won't overwrite them unless you delete them first.
Q: Do I need an API key?
- A: No! Multilingo is 100% free with no API keys required.
๐ค Contributing #
We welcome contributions from developers around the world! ๐
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Support & Community #
โญ Support Multilingo #
Enjoying Multilingo?
Click the link below and tap the ๐ LIKE button on pub.dev โ it really helps!
๐ https://pub.dev/packages/multilingo
Made with โค๏ธ in Egypt ๐ช๐ฌ | Spreading across the world ๐
Breaking language barriers, one app at a time