https://github.com/rtmigo/floca_flutter
Library for Flutter app localization. Generates Dart code with string constants, ready to plug into MaterialApp
https://github.com/rtmigo/floca_flutter
code-generator csv excel flutter i18n internationalization library localization spreadsheet static
Last synced: 4 months ago
JSON representation
Library for Flutter app localization. Generates Dart code with string constants, ready to plug into MaterialApp
- Host: GitHub
- URL: https://github.com/rtmigo/floca_flutter
- Owner: rtmigo
- License: mit
- Created: 2021-04-03T19:27:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-09-23T03:55:11.000Z (almost 2 years ago)
- Last Synced: 2025-01-21T15:32:13.727Z (6 months ago)
- Topics: code-generator, csv, excel, flutter, i18n, internationalization, library, localization, spreadsheet, static
- Language: Dart
- Homepage: https://pub.dev/packages/floca
- Size: 184 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pub.dev/packages/floca)
[](https://pub.dev/floca/tabular/score)# [floca](https://github.com/rtmigo/floca)
Floca is a **Fl**utter **loca**lization library.
Say, you have an Excel spreadsheet like this:
| property | en | es | ru | hi |
|----------|--------|---------|---------|-----|
| greeting | hi! | hola! | привет! | हाय! |
| farewell | bye | adiós | пока |अलविदा|Floca will let you access its content like this:
``` dart
Widget build(BuildContext context) {
// getting the strings in proper language
var a = context.i18n.greeting;
var b = context.i18n.farewell;
...
}
```# How Floca works
Floca is a command-line app, that takes your `.csv` spreadsheet and generates
a `.dart` file.Then you import the generated file in the project and get all the needed
functionality, including the localized strings:```dart
import "newly_generated.dart";
```This approach gives you maximum compatibility and performance.
In addition, many potential errors are prevented at compile time.# Install
Update `pubspec.yaml`:
``` yaml
dependencies:
flutter_localizations:
sdk: flutter
dev_dependencies:
floca: any
```Get:
``` bash
$ flutter pub get
```Check it runs:
``` bash
$ flutter pub run 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
```bash
$ flutter pub run floca string_constants.csv lib/string_constants.dart
```#### 3. Provide arguments to MaterialApp
``` dart
import 'string_constants.dart'; // file we created with flocaMaterialApp(
...
supportedLocales: supportedLocales, // add this
localizationsDelegates: localizationsDelegates, // and this
...
);
```#### 4. Get localized text in your app
``` dart
import 'string_constants.dart'; // file we created with flocaWidget build(BuildContext context) {
// now [context] has a new property [.i18n]
String s = context.i18n.greeting;
return Text(s);
}
```