Last updated:
0 purchases
gettext i18n
Flutter i18n with gettext #
This package helps internationalizing a Flutter application.
It is based on gettext and gettext_parser.
Features #
Supports from placeholders in the message keys
Usage #
Add this package, and flutter_localizations, to pubspec.yaml:
flutter pub add gettext_i18n
flutter pub add flutter_localizations --sdk=flutter
copied to clipboard
In pubspec.yaml, add assets/i18n/ as an asset folder:
flutter:
assets:
- assets/i18n/
copied to clipboard
Optionnal: in that folder, place your translation files:
$ ls assets/i18n/
en.po
fr_CH.po
fr.po
copied to clipboard
In your application file, declare supported locales, and initialize translations:
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
...
home: const HomePage(),
supportedLocales: const [
Locale('en'),
Locale('fr'),
Locale('fr', 'CH'),
],
localizationsDelegates: [
GettextLocalizationsDelegate(defaultLanguage: 'en'),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
);
}
}
copied to clipboard
In files where you want to translate a string :
import 'package:gettext_i18n/gettext_i18n.dart';
var translatedString = context.t('{2} ! Pi is greater than {0} and smaller than {1}', args: [3, 4, 'Hello']);
copied to clipboard
Additional information #
.po files can be edited by hand, but it's preferable to use an editor or an online service to manage them.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.