Class: RailsTranslationManager::Importer

Inherits:
Object
  • Object
show all
Includes:
YAMLWriter
Defined in:
lib/rails_translation_manager/importer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from YAMLWriter

#write_yaml

Constructor Details

#initialize(locale:, csv_path:, import_directory:, multiple_files_per_language:) ⇒ Importer

Returns a new instance of Importer.



10
11
12
13
14
15
# File 'lib/rails_translation_manager/importer.rb', line 10

def initialize(locale:, csv_path:, import_directory:, multiple_files_per_language:)
  @locale = locale
  @csv_path = csv_path
  @import_directory = import_directory
  @multiple_files_per_language = multiple_files_per_language
end

Instance Attribute Details

#csv_pathObject (readonly)

Returns the value of attribute csv_path.



8
9
10
# File 'lib/rails_translation_manager/importer.rb', line 8

def csv_path
  @csv_path
end

#import_directoryObject (readonly)

Returns the value of attribute import_directory.



8
9
10
# File 'lib/rails_translation_manager/importer.rb', line 8

def import_directory
  @import_directory
end

#localeObject (readonly)

Returns the value of attribute locale.



8
9
10
# File 'lib/rails_translation_manager/importer.rb', line 8

def locale
  @locale
end

#multiple_files_per_languageObject (readonly)

Returns the value of attribute multiple_files_per_language.



8
9
10
# File 'lib/rails_translation_manager/importer.rb', line 8

def multiple_files_per_language
  @multiple_files_per_language
end

Instance Method Details

#importObject



17
18
19
20
21
22
23
# File 'lib/rails_translation_manager/importer.rb', line 17

def import
  csv = reject_nil_keys(
    CSV.read(csv_path, encoding: "bom|utf-8", headers: true, header_converters: :downcase)
  )

  multiple_files_per_language ? import_csv_into_multiple_files(csv) : import_csv(csv)
end