floca 0.1.2-alpha copy "floca: ^0.1.2-alpha" to clipboard
floca: ^0.1.2-alpha copied to clipboard

outdated

Library for Flutter app localization. Generates Dart code with string constants, ready to plug into MaterialApp.

floca #

Floca is a Flutter localization 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:

Widget build(BuildContext context) {
  // getting the strings in proper language
  var a = context.i18n.greeting;
  var b = context.i18n.farewell;
  ...
}  

Floca is a code generator #

It takes your .csv spreadsheet and generates a .dart file.

import "newly_generated.dart";
  // this import adds the .i18n extension on BuildContext objects

This approach gives you maximum compatibility and performance. In addition, potential errors are prevented at compile time.

Widget build(BuildContext context) {
  var c = context.i18n.gritting; // COMPILE-TIME ERROR!
  ...
}  

Install #

Update pubspec.yaml:

dependencies:
  floca: any

Get:

$ flutter pub get

Check it runs:

$ 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

$ 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); 
}
2
likes
0
points
6
downloads

Publisher

verified publisherrevercode.com

Weekly Downloads

Library for Flutter app localization. Generates Dart code with string constants, ready to plug into MaterialApp.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

csv, flutter, flutter_localizations, intl

More

Packages that depend on floca