smart_arb_translator 1.0.1
smart_arb_translator: ^1.0.1 copied to clipboard
An intelligent command-line utility for translating ARB files with Google Translate API, featuring smart change detection and modular architecture.
example/README.md
Smart ARB Translator Examples #
This directory contains comprehensive examples demonstrating Smart ARB Translator's complete workflow, including the new Dart code generation feature.
π NEW: Complete Flutter Integration #
Smart ARB Translator now provides end-to-end Flutter internationalization: Translation β ARB Files β Dart Code β Ready-to-use Flutter App
π Directory Structure #
example/
βββ README.md # This file
βββ flutter_app/ # Complete Flutter example app
β βββ lib/
β β βββ main.dart # Flutter app using generated localizations
β β βββ l10n/ # Source ARB files
β β β βββ app_en.arb
β β βββ generated/ # Generated Dart code (auto-created)
β βββ pubspec.yaml
β βββ api_key.txt # Your Google API key
βββ sample_arb_files/ # Sample ARB files for testing
β βββ app_en.arb
β βββ common_en.arb
β βββ features/
β βββ auth_en.arb
β βββ profile_en.arb
βββ scripts/
β βββ complete_workflow.sh # NEW: Translation + Dart generation
β βββ translate_only.sh # Translation only
β βββ test_with_api.sh # Test with provided API key
βββ programmatic/
βββ basic_usage.dart
βββ advanced_usage.dart
π Quick Start: Complete Workflow #
Option 1: One Command Solution (NEW!) #
# Complete workflow: Translate + Generate Dart code
smart_arb_translator \
--source_dir example/flutter_app/lib/l10n \
--api_key example/flutter_app/api_key.txt \
--language_codes es,fr,de,ja \
--generate_dart \
--dart_class_name AppLocalizations \
--dart_output_dir example/flutter_app/lib/generated
Option 2: Step by Step #
# Step 1: Translate ARB files
smart_arb_translator \
--source_dir example/flutter_app/lib/l10n \
--api_key example/flutter_app/api_key.txt \
--language_codes es,fr,de,ja
# Step 2: Generate Dart code
smart_arb_translator \
--source_dir example/flutter_app/lib/l10n \
--api_key example/flutter_app/api_key.txt \
--language_codes es,fr,de,ja \
--generate_dart
π― Live Example: Flutter App #
1. Setup the Example App #
cd example/flutter_app
# Add your API key
echo "ENTER_API_KEY_HERE" > api_key.txt
# Install dependencies
flutter pub get
2. Run Complete Translation + Code Generation #
smart_arb_translator \
--source_dir lib/l10n \
--api_key api_key.txt \
--language_codes es,fr,de,ja \
--generate_dart \
--dart_class_name AppLocalizations
3. Run the Flutter App #
flutter run
The app will now support multiple languages with type-safe, auto-generated localization code!
π Sample ARB Files #
Main App Strings (app_en.arb) #
{
"@@locale": "en",
"@@last_modified": "2024-01-01T00:00:00.000Z",
"appTitle": "Smart ARB Translator Demo",
"@appTitle": {
"description": "The title of the application"
},
"welcomeMessage": "Welcome to Smart ARB Translator!",
"@welcomeMessage": {
"description": "Welcome message shown to users"
},
"itemCount": "{count,plural, =0{No items} =1{One item} other{{count} items}}",
"@itemCount": {
"description": "Shows the number of items",
"placeholders": {
"count": {
"type": "int"
}
}
},
"greetUser": "Hello, {name}!",
"@greetUser": {
"description": "Greets the user by name",
"placeholders": {
"name": {
"type": "String"
}
}
}
}
π§ Advanced Features #
Manual Translation Overrides #
{
"specialGreeting": "Hello there!",
"@specialGreeting": {
"description": "A special greeting",
"@x-translations": {
"es": "Β‘Hola amigo!",
"fr": "Salut mon ami!",
"de": "Hallo mein Freund!"
}
}
}
Smart Change Detection #
# Only translates new or modified keys (saves API costs!)
smart_arb_translator \
--source_dir lib/l10n \
--api_key api_key.txt \
--language_codes es,fr \
--generate_dart
Custom Configuration #
smart_arb_translator \
--source_dir lib/l10n \
--api_key api_key.txt \
--language_codes es,fr,de,ja,ko,zh \
--generate_dart \
--dart_class_name MyAppLocalizations \
--dart_output_dir lib/i18n \
--dart_main_locale en \
--cache_directory .translation_cache \
--l10n_directory lib/l10n_merged
π± Flutter Integration Example #
Generated Usage (After running with --generate_dart) #
import 'package:flutter/material.dart';
import 'lib/generated/l10n.dart'; // Auto-generated!
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Smart ARB Translator Demo',
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Scaffold(
appBar: AppBar(
title: Text(l10n.appTitle), // Type-safe!
),
body: Column(
children: [
Text(l10n.welcomeMessage),
Text(l10n.greetUser('John')), // With parameters!
Text(l10n.itemCount(5)), // Plural support!
],
),
);
}
}
π§ͺ Testing Scripts #
Test with Provided API Key #
# Use the provided test API key
./scripts/test_with_api.sh
Complete Workflow Test #
# Test the entire translation + code generation workflow
./scripts/complete_workflow.sh
π Performance Benefits #
| Feature | Before | After (Smart ARB Translator) |
|---|---|---|
| Setup Time | 30+ minutes | 2 minutes |
| Translation Cost | Full retranslation | Only changed content |
| Code Generation | Manual setup | Automatic |
| Type Safety | Runtime errors | Compile-time safety |
| Maintenance | Multiple tools | Single command |
π Supported Languages #
Test with multiple languages:
smart_arb_translator \
--source_dir lib/l10n \
--api_key api_key.txt \
--language_codes es,fr,de,it,pt,ru,ja,ko,zh,ar,hi,th \
--generate_dart
π Troubleshooting #
Common Issues & Solutions #
-
API Key Issues
# Verify API key echo "ENTER_API_KEY_HERE" > api_key.txt -
Permission Errors
# Fix permissions chmod -R 755 lib/ -
Dart Generation Fails
# Ensure pubspec.yaml exists flutter create . --project-name my_app -
Missing Dependencies
# Install required dependencies dart pub add intl flutter pub get
π Learning Path #
- π’ Beginner: Run
./scripts/test_with_api.sh - π‘ Intermediate: Modify
example/flutter_app/lib/l10n/app_en.arb - π Advanced: Create custom ARB structure
- π΄ Expert: Integrate into existing Flutter project
π What's New in v1.0.0 #
- β Dart Code Generation: Complete intl_utils integration
- β One Command Solution: Translation + code generation
- β Type Safety: Compile-time localization safety
- β Smart Caching: Only translate what changed
- β Flutter Ready: Drop-in Flutter integration
π Getting Help #
- π Main Documentation
- π Report Issues
- π‘ Feature Requests
- π― Live Examples
Ready to revolutionize your Flutter i18n workflow? πβ¨