Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lukas-h/sheets_i18n
https://github.com/lukas-h/sheets_i18n
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/lukas-h/sheets_i18n
- Owner: lukas-h
- License: mit
- Created: 2024-09-23T06:57:57.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-11-05T13:27:16.000Z (2 months ago)
- Last Synced: 2024-11-05T13:34:13.398Z (2 months ago)
- Language: Dart
- Size: 108 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# sheets_i18n
A flutter tool to synchronize i18n (internationalization) arb files with google sheets.
## Usage
### 1. Prepare a Google Sheet Document
You can get the sample here: [docs.google.com](https://docs.google.com/spreadsheets/d/1FY5zf1ngPyFsnv5F15BafzVA7UYi0kP3cZ4LE3XhZzY/edit?usp=sharing)
It should look like this:
- the first column is the message key (used to lookup the translation in the app).
- the columns after that are the language codes.
- the rows are for each specific translated word/sentence.- copy the sheet ID: `https://docs.google.com/spreadsheets/d/THIS PART OF THE URL/edit?pli=1&gid=0#gid=0`
### 2. Configure a service account
1. Create a new service account in the Google Cloud Console
2. Turn on the Google Sheets API
3. Copy the service account's email address
4. Share the google sheet with the service account and give it edit privileges
5. Download the service account JSON (it's local path will later be added to the pubspec configuration)⚠️ DO NOT COMMIT YOUR SERVICE ACCOUNT JSON ⚠️
### 3. Prerequisites with `intl_translation`
1. Having setup `intl_translation` and `flutter_localizations`, incl. a `MyAppLocalizations` and `MyAppLocalizationsDelegate` class ([see our example app](https://github.com/lukas-h/sheets_i18n/tree/main/example))
2. Having run the `intl_translation` commands to generate the arb files [github.com/dart-lang/i18n](https://github.com/dart-lang/i18n/tree/main/pkgs/intl_translation#extracting-and-using-translated-messages)
```bash
flutter pub run intl_translation:extract_to_arb --output-dir=lib/l10n lib/localizations.dart
```
3. Create new ARB files for each locale, naming them `intl_.arb` (e.g., `intl_de.arb` for German, `intl_es.arb` for Spanish).### 4. Install this package
```bash
flutter pub add sheets_i18n
```### 5. Configure the pubspec.yaml
add this section:
```yaml
sheets_i18n:
service_account_path: ./path/to/service_account.json
sheet_id: 34tv34rv324rv23rv3r43r43red89f8hs89duzfs
localizations_file: './lib/localizations.dart' # file with the localization messages - optional - default is ./lib/main.dart
localizations_path: './lib/l10n' # folder for arb files - optional - default is ./lib/l10n
```### 6. Run the sync script
```bash
flutter pub run sheets_i18n:update
```This will 2-way-sync all the changes:
- message keys that are not present in the Google Sheet will be added
- new translations will be pulled and written to the arb files### 7. Run `intl_translation`'s arb to dart
Run the `intl_translation` commands to generate the dart code from the arb files [github.com/dart-lang/i18n](https://github.com/dart-lang/i18n/tree/main/pkgs/intl_translation#extracting-and-using-translated-messages)
```bash
flutter pub run intl_translation:generate_from_arb \
--output-dir=lib/l10n --no-use-deferred-loading \
lib/localizations.dart \
lib/l10n/intl_en.arb lib/l10n/intl_de.arb lib/l10n/intl_cs.arb
```