Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-12T02:02:37.000Z (over 2 years ago)
- Last Synced: 2023-08-20T21:57:37.902Z (over 1 year ago)
- Topics: code-generator, csv, excel, flutter, i18n, internationalization, library, localization, spreadsheet, static
- Language: Dart
- Homepage: https://pub.dev/packages/floca
- Size: 181 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![Pub Package](https://img.shields.io/pub/v/floca.svg)](https://pub.dev/packages/floca)
[![pub points](https://badges.bar/floca/pub%20points)](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);
}
```