Download a CSV file and generate localization keys from an online Google Sheet to work with easy_localization and easy_localization_loader.
This tool is inspired by flutter_sheet_localization_generator and the original author RinLV.
Add to your pubspec.yaml
:
dependencies:
easy_localization: <latest_version>
easy_localization_loader: <latest_version>
dev_dependencies:
build_runner: <latest_version>
sheet_loader_localization: <latest_version>
Create a sheet with your translations (follow the format below; example sheet here):
There are two options:
-
If your Google Sheet is public, keep the setup as-is.
-
If your Google Sheet is private, follow these steps:
-
Enable Google Drive API and Generate an API Key
Follow this guide: How to Use Google Drive API and Get an API Key -
Set the
apiKey
parameter in the@SheetLocalization
annotation.
-
Create a Dart file (lib/utils/multi-languages/locale_keys.dart
) with the following content:
import 'dart:ui';
import 'package:sheet_loader_localization/sheet_loader_localization.dart';
part 'locale_keys.g.dart';
@SheetLocalization(
docId: 'DOCID',
version: 1,
outDir: 'resources/langs',
outName: 'langs.csv',
preservedKeywords: [],
// OPTIONAL: Only required if your sheet is private
apiKey: 'YOUR_GOOGLE_API_KEY',
)
class _LocaleKeys {}
Run the command below to generate the localization file:
flutter pub run build_runner build
# or
flutter pub run build_runner build --delete-conflicting-outputs
Follow the setup guide from the easy_localization README.
To force regeneration of the CSV and localization files (due to caching), simply increment the version
field in @SheetLocalization
and rerun the build command.
easy_localization
supports code generation, but not directly from Google Sheets. This tool simplifies localization workflows by using Google Sheets (ideal for collaboration with non-devs) and supports Flutter null safety.