easy_localization_generator 0.0.2
easy_localization_generator: ^0.0.2 copied to clipboard

Download CSV file and generates the localization keys from an online Google Sheet.

easy_localization_generator #

Pub Code Climate issues GitHub closed issues GitHub contributors GitHub repo size GitHub forks GitHub stars GitHub license

Easy Localization Generator #

Download CSV file and generates the localization keys from an online Google Sheet to working with easy_localization and easy_localization_loader

This tool inspired by flutter_sheet_localization_generator

🔩 Installation #

Add to your pubspec.yaml:

dependencies:
  easy_localization: <last_version>
  easy_localization_loader: <last_version>

dev_dependencies:
  build_runner: <last_version>
  easy_localization_generator: <last_version>

🔌 Usage #

1. Create a CSV Google Sheet

Create a sheet with your translations (following the bellow format, an example sheet is available here) :

csv example file

Make sure that your sheet is shared :

share

Extract from the link the DOCID value : https://docs.google.com/spreadsheets/d/<DOCID>/edit?usp=sharing) :

2. Declare a localization delegate

Declare the following _LocaleKeys class with the SheetLocalization annotation pointing to your sheet in a lib/localization/locale_keys.dart file :

import 'dart:ui';

import 'package:easy_localization_generator/easy_localization_generator.dart';

part 'locale_keys.g.dart';

@SheetLocalization(
    docId: 'DOCID',
    version: 1, // the `1` is the generated version.
    //You must increment it each time you want to regenerate a new version of the labels.
    outDir: 'resources/langs', //default directory save downloaded CSV file
    outName: 'langs.csv', //default CSV file name
    preservedKeywords: [
      'few',
      'many',
      'one',
      'other',
      'two',
      'zero',
      'male',
      'female',
    ])
class _LocaleKeys {}

3. Generate your localizations

Run the following command to generate a lib/localization/locale_keys.g.dart file :

flutter pub run build_runner build

Sample of locale_keys.g.dart

4. Configure your app

Last, config step by step following this tutorial from README.md of easy_localization

⚡ Regeneration #

Because of the caching system of the build_runner, it can't detect if there is a change on the distant sheet and it can't know if a new generation is needed.

The version parameter of the @SheetLocalization annotation solves this issue.

Each time you want to trigger a new generation, simply increment that version number and call the build runner again.

❓️ Why ? #

I find the easy_localization has already Code generation, but it doesn't support working with Google Sheet and generate keys from CSV file. So, I make this simple generator tool.

1
likes
80
pub points
44%
popularity

Publisher

Unknown

Download CSV file and generates the localization keys from an online Google Sheet.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

analyzer, build, build_config, csv, flutter, http, intl, path, source_gen

More

Packages that depend on easy_localization_generator