verba_translations
Verba for Flutter. One package with two jobs:
- CLI (
dart run verba_translations) — pushes new keys from your ARB files to Verba (with a write token) and fetches approved translations back into the ARB files thatflutter gen-l10ncompiles; - OTA runtime (optional) — texts changed in Verba show up in the running app, without a new release.
Setup
flutter pub add verba_translations
pubspec.yaml (standard gen-l10n plus a verba section):
dependencies:
flutter_localizations:
sdk: flutter
intl: any
flutter:
generate: true
verba:
project: my-project
Tokens are looked up in this order (files next to pubspec.yaml — add them to .gitignore):
| env | file | |
|---|---|---|
| read (fetch, OTA) | VERBA_TOKEN |
.verba-token |
| write (push) | VERBA_WRITE_TOKEN |
.verba-write-token |
Generate them in Verba: project → Settings → Package keys.
Fetch + push
dart run verba_translations && flutter run
With a write token it pushes first, then fetches: keys that exist only in your ARB files are created in Verba with their texts, and empty values in Verba are filled in. Anything already in Verba is never overwritten (Verba is the source of truth), and keys deleted in Verba are not revived. If the push of a locale fails, its file is not overwritten by the fetch.
- push only:
dart run verba_translations --push - fetch without the automatic push:
--no-push - without a write token, fetch rewrites the files with what is in Verba — a key added only locally is lost;
- the ARB files are generated by Verba: local metadata (
description,example) is not kept; placeholders get types (String,count→int).
Fail-soft: no token / offline / error → a warning, exit code 0, existing files are kept.
What is inferred
| Setting | Default |
|---|---|
locales |
from Verba (by token); pin them with verba: locales: [en, ro] |
| folder | arb-dir from l10n.yaml (default lib/l10n) |
| file names | from template-arb-file (default app_en.arb): app_<locale>.arb, pt-BR → app_pt_BR.arb |
| base locale | pt_BR without pt in Verba → app_pt.arb is written too (gen-l10n requires it) |
| escaping | use-escaping from l10n.yaml |
| server | https://verba.kred; self-hosted: verba: server: https://… |
Conversions
| Verba | ARB |
|---|---|
{name} |
{name} |
{0}, %1$s |
{arg0} (placeholders must be Dart identifiers) |
files__one, files__other (%d) |
{count, plural, one{{count} …} other{{count} …}} |
MD-{{AAAA}} (literal braces) |
with use-escaping: true: MD-'{'AAAA'}' (and ' → ''); without it: MD-{AAAA} |
Keys that cannot be Dart getters (home.title, Title, 1st, class) are skipped — gen-l10n would reject the
whole file. Complex ICU messages (select, a plural in the middle of a text) pass through unchanged both ways.
OTA at runtime (optional)
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await VerbaOta.start(project: 'my-project'); // read token: --dart-define=VERBA_TOKEN=…
runApp(const VerbaScope(child: MyApp()));
}
// in a widget — Verba first, then the compiled gen-l10n text
final l = AppLocalizations.of(context)!;
Text(VerbaOta.text(context, 'greeting', {'name': user}) ?? l.greeting(user))
Text(VerbaOta.text(context, 'files', {'count': n}) ?? l.files(n))
flutter run --dart-define=VERBA_TOKEN=$(cat .verba-token)
- no network on the render path: an in-memory map; on start, the last downloaded texts (
shared_preferences); - background download on start and whenever the app returns to the foreground, one conditional request per
locale (ETag →
304); optionallyinterval:; manuallyVerbaOta.refresh(); - Verba unreachable → the last good texts stay (or the compiled ones), with a single warning;
- placeholders, plural (CLDR rules from
intl) and select, like gen-l10n; a text that cannot be formatted (missing argument) yieldsnull→ the compiled text; - under
VerbaScope, widgets that read throughVerbaOta.textrebuild when new texts arrive; without a context:VerbaOta.get('ro', 'greeting', {'name': user}); use-escaping: trueinl10n.yaml→VerbaOta.start(..., escaping: true).
Example
example/ — a minimal app (run flutter create . in the folder to add platforms).
Development
flutter pub get && flutter analyze && flutter test
Libraries
- verba_translations
- Verba OTA for Flutter: texts changed in Verba show up in the app without a new release.