Class: RailsTranslationManager::Exporter
- Inherits:
-
Object
- Object
- RailsTranslationManager::Exporter
- Defined in:
- lib/rails_translation_manager/exporter.rb
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(directory, source_locale_path, target_locale_path) ⇒ Exporter
constructor
A new instance of Exporter.
Constructor Details
#initialize(directory, source_locale_path, target_locale_path) ⇒ Exporter
Returns a new instance of Exporter.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rails_translation_manager/exporter.rb', line 9 def initialize(directory, source_locale_path, target_locale_path) @source_locale_path = source_locale_path @target_locale_path = target_locale_path @source_locale = File.basename(target_locale_path).split(".")[0] @target_locale = File.basename(target_locale_path).split(".")[0] @output_path = File.join(directory, @target_locale + ".csv") @keyed_source_data = translation_file_to_keyed_data(source_locale_path, @source_locale) @keyed_target_data = translation_file_to_keyed_data(target_locale_path, @target_locale) end |
Instance Method Details
#export ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rails_translation_manager/exporter.rb', line 20 def export csv = CSV.generate do |csv| csv << CSV::Row.new(["key", "source", "translation"], ["key", "source", "translation"], true) @keyed_source_data.keys.sort.each do |key| if key =~ /^language_names\./ next unless key =~ /#{@target_locale}$/ end if is_pluralized_key?(key) export_pluralization_rows(key, csv) else csv << export_row(key, @keyed_source_data[key], @keyed_target_data[key]) end end end File.open(@output_path, "w") { |f| f.write csv.to_s } end |