Class: I18nAdd::YamlProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_add/yaml_processor.rb

Defined Under Namespace

Classes: KeyContext, ProcessorState, TranslationEntry

Instance Method Summary collapse

Instance Method Details

#process_files(file_map) ⇒ void

Note:

The method automatically creates directory structures and files if they don’t exist

Note:

Existing YAML content is preserved and new keys are properly merged

Note:

Console output shows processing progress and completion status

This method returns an undefined value.

Processes multiple YAML translation files with their respective locale configurations.

This is the main entry point for the YAML processor. It handles batch processing of translation entries across multiple files, ensuring that each file is properly updated with new translation keys while preserving existing content and structure.

The method creates necessary directory structures, handles file creation if files don’t exist, and maintains proper YAML formatting throughout the process.

Examples:

Processing translations for multiple locales

processor = YamlProcessor.new
file_map = {
  'config/locales/en/main.en.yml' => {
    locale: 'en',
    entries: [
      { key_path: 'app.title', value: 'My Application' },
      { key_path: 'nav.home', value: 'Home' }
    ]
  },
  'config/locales/es/main.es.yml' => {
    locale: 'es',
    entries: [
      { key_path: 'app.title', value: 'Mi Aplicación' },
      { key_path: 'nav.home', value: 'Inicio' }
    ]
  }
}
processor.process_files(file_map)

Processing a single file

file_map = {
  'translations.yml' => {
    locale: 'en',
    entries: [{ key_path: 'greeting', value: 'Hello World' }]
  }
}
processor.process_files(file_map)

Parameters:

  • file_map (Hash<String, Hash>)

    A hash mapping file paths to their configurations

  • entries (Hash)

    a customizable set of options

Options Hash (file_map):

  • :locale (String)

    The locale identifier (e.g., ‘en’, ‘es’, ‘fr’)

  • :entries (Array<Hash>)

    Array of translation entries to process

See Also:

  • #process_single_file

Since:

  • 1.0.0



58
59
60
61
62
63
# File 'lib/i18n_add/yaml_processor.rb', line 58

def process_files(file_map)
  file_map.each do |file_path, config|
    process_single_file(file_path, config)
  end
  puts "Processed #{file_map.size} files successfully."
end