4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/ad_localize/mappers/csv_path_to_wording.rb', line 4
def map(csv_path:)
@headers = CSV.foreach(csv_path).first
return unless valid?(csv_path: csv_path)
translations = []
validator = Validators::KeyValidator.new
CSV.foreach(csv_path, headers: true, skip_blanks: true) do |row|
row_translations = map_row(row: row, locales: locales)
next if row_translations.blank?
current_key = row_translations.first.key
next if validator.has_warnings?(current_key)
translations.concat(row_translations)
end
locale_wordings = translations.group_by(&:locale).map do |locale, group|
Entities::LocaleWording.new(locale: locale, translations: group)
end
Entities::Wording.new(locale_wordings: locale_wordings, default_locale: locales.first)
end
|