EzI18n ๐โจ
EzI18n is a lightweight internationalization (i18n) library for Flutter. It simplifies managing translations and supports dynamic parameter replacement, making multilingual apps easy to develop. ๐
Features ๐ ๏ธ
- ๐ Support for generic (
pt
) and specific (pt_BR
) locales. - ๐ Dynamic parameter replacement (
@{name}
). - ๐ก๏ธ Fallback mechanism for missing translations.
- ๐ฆ Seamless integration with Flutter's localization framework.
Getting Started ๐
Installation ๐ฅ
Add EzI18n to your pubspec.yaml
:
dependencies:
ezi18n: ^1.0.0
Run:
flutter pub get
Observation ๐
For native Widget translation, you will need the flutter_localizations
package to use the delegates, as shown in the example below.
Usage ๐
- Define translations: ๐๏ธ
import 'package:ezi18n/ezi18n.dart';
class AppMessages implements EzMessages {
@override
Map<String, Map<String, String>> get keys => {
'en': {'greeting': 'Hello, @{name}!'},
'pt': {'greeting': 'Olรก, @{name}!'},
};
}
- Set up localization in your app: โ๏ธ
import 'package:ezi18n/ezi18n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
locale: Locale('en'),
localizationsDelegates: [
EzI18nDelegate(AppMessages()),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [Locale('en'), Locale('pt')],
home: MyHomePage(),
);
}
}
- Use translations: ๐
import 'package:flutter/material.dart';
import 'package:ezi18n/ezi18n.dart';
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('greeting'.tr(context, params: {'name': 'Alice'}))),
body: Center(child: Text('greeting'.tr(context, params: {'name': 'Alice'}))),
);
}
}
Contributions ๐ค
Contributions are welcome! ๐ Feel free to open issues or submit PRs on GitHub.
License ๐
EzI18n is available under the MIT license. ๐ก๏ธ