smart_arb_translator 1.0.1 copy "smart_arb_translator: ^1.0.1" to clipboard
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 #

  1. API Key Issues

    # Verify API key
    echo "ENTER_API_KEY_HERE" > api_key.txt
    
  2. Permission Errors

    # Fix permissions
    chmod -R 755 lib/
    
  3. Dart Generation Fails

    # Ensure pubspec.yaml exists
    flutter create . --project-name my_app
    
  4. Missing Dependencies

    # Install required dependencies
    dart pub add intl
    flutter pub get
    

πŸ“š Learning Path #

  1. 🟒 Beginner: Run ./scripts/test_with_api.sh
  2. 🟑 Intermediate: Modify example/flutter_app/lib/l10n/app_en.arb
  3. 🟠 Advanced: Create custom ARB structure
  4. πŸ”΄ 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 #


Ready to revolutionize your Flutter i18n workflow? πŸš€βœ¨

5
likes
0
points
26
downloads

Publisher

verified publisherabcx3.com

Weekly Downloads

An intelligent command-line utility for translating ARB files with Google Translate API, featuring smart change detection and modular architecture.

Homepage
Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

arb_merge, args, collection, console, html_unescape, http, intl_utils, path, petitparser, yaml

More

Packages that depend on smart_arb_translator