Skip to content

Commit

Permalink
Fixes bug downloading source: `to_json': "\\xE2" from ASCII-8BIT to U…
Browse files Browse the repository at this point in the history
…TF-8 (Encoding::UndefinedConversionError)
  • Loading branch information
joaoffcosta committed Aug 30, 2021
1 parent 08a2d18 commit 9806919
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/bisu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def i18n_for(config:, options:)

save_to_path = options[:dictionary_save_path]
if save_to_path && file = open_file(save_to_path, "w", false)
file.write(source.to_json)
file.write(deep_force_encoding(source).to_json)
file.flush
file.close
end
Expand Down Expand Up @@ -149,4 +149,15 @@ def localize_file(localizer, locale, language, fallback_languages, in_path, out_

true
end

def deep_force_encoding(hash)
hash.each do |_, value|
case value
when String
value.force_encoding(Encoding::UTF_8)
when Hash
deep_force_encoding(value)
end
end
end
end

0 comments on commit 9806919

Please sign in to comment.