ai_translation_generator 1.0.2 copy "ai_translation_generator: ^1.0.2" to clipboard
ai_translation_generator: ^1.0.2 copied to clipboard

A professional CLI tool for AI-powered translation generation using Google's Gemini AI. Generate Flutter l10n files with ease.

example/example.dart

// Copyright (c) 2024 AI Translation Generator
// Licensed under the MIT License

/// Example usage of AI Translation Generator
///
/// This example demonstrates how to use the AI Translation Generator
/// to create Flutter l10n translation files programmatically.
///
/// ## Setup
///
/// 1. Set your Gemini API key:
///    ```bash
///    export GEMINI_API_KEY=your_gemini_api_key_here
///    ```
///
/// 2. Run this example:
///    ```bash
///    dart run example/example.dart
///    ```
library;

import 'dart:io';
import 'package:ai_translation_generator/ai_translation_generator.dart';

Future<void> main() async {
  print('šŸš€ AI Translation Generator Example');
  print('=====================================\n');

  try {
    // Create a sample configuration
    final config = TranslationConfig(
      languages: ['en', 'ar', 'es', 'fr'],
      strings: [
        'welcome',
        'settings',
        'profile',
        'logout',
        'search',
        'filter',
        'save',
        'cancel',
      ],
    );

    print('šŸ“‹ Configuration:');
    print('Languages: ${config.languages.join(', ')}');
    print('Strings: ${config.strings.length} strings to translate\n');

    // Create services
    final geminiService = GeminiService();
    final translationService = TranslationService(
      geminiService: geminiService,
      config: config,
    );

    print('šŸ”§ Services initialized successfully\n');

    // Check internet connectivity
    print('🌐 Checking internet connectivity...');
    final hasConnection = await geminiService.checkConnectivity();
    if (!hasConnection) {
      print('āŒ No internet connection. Please check your network.');
      return;
    }
    print('āœ… Internet connection verified\n');

    // Generate translations
    print('šŸ”„ Generating translations...');
    final translations = await translationService.generateTranslations(
      onProgress: (message) {
        print('   $message');
      },
      onLanguageComplete: (message) {
        print('   āœ… $message');
      },
    );

    print('\nšŸ’¾ Saving translation files...');
    await translationService.saveTranslations(translations);

    print('\nšŸŽ‰ Translation generation completed!');
    print('šŸ“ Generated files:');
    for (final language in config.languages) {
      print('   - lib/l10n/$language.json');
    }

    print('\nšŸ“– Next steps:');
    print('1. Copy the generated files to your Flutter project');
    print('2. Configure your Flutter app for l10n');
    print('3. Use the translations in your app');
  } catch (e) {
    print('āŒ Error: $e');
    print('\nšŸ’” Make sure to set your GEMINI_API_KEY environment variable');
    print('   export GEMINI_API_KEY=your_gemini_api_key_here');
    exit(1);
  }
}
0
likes
160
points
159
downloads

Publisher

unverified uploader

Weekly Downloads

A professional CLI tool for AI-powered translation generation using Google's Gemini AI. Generate Flutter l10n files with ease.

Repository (GitHub)
View/report issues
Contributing

Documentation

API reference

License

MIT (license)

Dependencies

args, cli_util, dotenv, http, io, path, yaml

More

Packages that depend on ai_translation_generator