mayr_i18n_generation 1.0.0 copy "mayr_i18n_generation: ^1.0.0" to clipboard
mayr_i18n_generation: ^1.0.0 copied to clipboard

Provide automatic type-safe translation key generation for projects using mayr_i18n.

1.0.0 #

πŸŽ‰ Initial Release #

A complete Dart code generation package for type-safe i18n translation keys.

Features

  • ✨ Type-safe translation keys - Generate Dart classes from JSON translation files
  • πŸ—οΈ build_runner integration - Automatic code generation with build_runner
  • πŸ”§ CLI tool for manual code generation:
    • generate - Automatically creates output file and generates translation keys
  • πŸ“¦ Nested JSON support - Handle deeply nested translation structures
  • 🌐 Multi-locale support - Manage multiple language files easily
  • 🎯 Targeted generation - Configure which file to process via output_file to avoid conflicts with other generators
  • πŸš€ Automatic file creation - CLI command creates the output file with proper structure if it doesn't exist
  • πŸ”’ Unique class names - Uses full path for nested class names to prevent conflicts (e.g., _ProfileDetailsKeys, _UserDetailsKeys)
  • πŸ“ Comprehensive documentation - Full API docs and examples
  • βœ… Well-tested - Extensive test coverage for all components

Note: Commands for verifying, syncing, and auditing translations are available in the mayr_i18n package.

Configuration

mayr_i18n:
  lang_directory: assets/lang
  default_locale: en

mayr_i18n_generation:
  output_file: lib/translations.dart  # Default: lib/generated/translations.dart

The output_file configuration specifies which file to create and process. The CLI command will automatically create this file (with the necessary part directive) if it doesn't exist, then generate the .g.dart file with translation keys.

Core Components

  • I18nConfig - Read and manage i18n configuration from pubspec.yaml
  • GeneratorConfig - Read generator-specific settings (output_file)
  • JsonParser - Parse and validate JSON translation files
  • KeyTreeBuilder - Build hierarchical key structures
  • CodeEmitter - Generate clean, readable Dart code
  • I18nGenerator - build_runner integration for automatic generation

Example Usage

// Define translations in JSON
{
  "app": {
    "welcome": "Welcome {name}!",
    "logout": "Goodbye"
  }
}

// Access with type-safe keys
I18nKeys.app.welcome.tr(args: {'name': 'John'});

See the README.md for complete documentation and example/ for working examples.

0
likes
150
points
32
downloads

Publisher

verified publishermayrlabs.com

Weekly Downloads

Provide automatic type-safe translation key generation for projects using mayr_i18n.

Repository (GitHub)
View/report issues
Contributing

Topics

#i18n #dart #json-translation #productivity #development

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

analyzer, args, build, glob, path, source_gen, yaml

More

Packages that depend on mayr_i18n_generation