floca 0.1.0-alpha floca: ^0.1.0-alpha copied to clipboard
Flutter localization library
Install #
Update pubspec.yaml
:
dependencies:
floca: any
Get:
$ flutter pub get
Check it runs:
$ flutter pub run floca:floca --help
Use #
1. Create the spreadsheet
property | en | es | ru | hi |
---|---|---|---|---|
greeting | hi! | hola! | привет! | हाय! |
farewell | bye | adiós | пока | अलविदा |
Save it as .csv
file, say, string_constants.csv
.
2. Generate a .dart file from it
$ flutter pub run floca:floca string_constants.csv string_constants.dart
3. Provide arguments to MaterialApp
import 'string_constants.dart'; // file we created with floca
MaterialApp(
...
supportedLocales: supportedLocales, // add this
localizationsDelegates: localizationsDelegates, // and this
...
);
4. Get localized text in your app
import 'string_constants.dart'; // file we created with floca
Widget build(BuildContext context) {
// now [context] has a new property [.i18n]
String s = context.i18n.greeting;
return Text(s);
}