From 98069196669fefad0dc9c75b61f097bcc03122a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Costa?= Date: Mon, 30 Aug 2021 16:12:26 +0100 Subject: [PATCH] Fixes bug downloading source: `to_json': "\\xE2" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) --- lib/bisu.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/bisu.rb b/lib/bisu.rb index a97556f..ae08ef0 100644 --- a/lib/bisu.rb +++ b/lib/bisu.rb @@ -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 @@ -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