Skip to content

Commit

Permalink
refactor csv value quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
tarix committed May 24, 2015
1 parent 137718e commit 915f3af
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/i18n-docs/sub_translation.rb
Expand Up @@ -119,6 +119,12 @@ def is_google_drive?
# IMPORT #
##########

def encode_csv_value(value)
return value if value.nil? || value.empty?
new_value = value.gsub('"', '\"')
"\"#{new_value}\""
end

def load_csv
CSV.foreach(tmp_file, headers: true) do |row|
row_hash = row.to_hash
Expand All @@ -127,7 +133,7 @@ def load_csv

manager.locales.each do |locale|
raise "Locale missing for key #{key}! (locales in app: #{locales} / locales in file: #{row_hash.keys.to_s})" unless row_hash.has_key?(locale)
self.flat_translations[locale][key] = "'#{row_hash[locale]}'"
self.flat_translations[locale][key] = encode_csv_value(row_hash[locale])
end
end
end
Expand Down

0 comments on commit 915f3af

Please sign in to comment.