floca

Floca is a Flutter localization library.

Say, you have an Excel spreadsheet like this:

propertyenesruhi
greetinghi!hola!привет!हाय!
farewellbyeadió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;
  ...
}  

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:

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:

dependencies:
  flutter_localizations:
    sdk: flutter
    
dev_dependencies:
  floca: any

Get:

$ flutter pub get

Check it runs:

$ flutter pub run floca --help

Use

1. Create the spreadsheet

propertyenesruhi
greetinghi!hola!привет!हाय!
farewellbyeadiósпокаअलविदा

Save it as .csv file, say, string_constants.csv.

2. Generate a .dart file from it

$ flutter pub run floca string_constants.csv lib/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); 
}

Libraries

floca