v0.4 - Add debugging

This commit is contained in:
David Sainty 2024-09-09 17:30:37 +10:00
parent 15d6539bc1
commit 655a2619f8

View File

@ -1,7 +1,7 @@
# Federated Computer, Inc. # Federated Computer, Inc.
# David Sainty <saint@federated.computer> 2024 A.D. # David Sainty <saint@federated.computer> 2024 A.D.
# Gossamer Threads to Discourse -- Correct Encoding # Gossamer Threads to Discourse -- Correct Encoding
# v0.3 Debugging # v0.4 Debugging
require 'mysql2' require 'mysql2'
require 'active_record' require 'active_record'
@ -37,8 +37,11 @@ class GossamerForumsCorrectEncoding < ImportScripts::Base
original_encoding = detection[:encoding] original_encoding = detection[:encoding]
puts "Original encoding detected: #{original_encoding}" puts "Original encoding detected: #{original_encoding}"
if original_encoding == 'ISO-8859-1' # Force the encoding to the detected one, then covnert to UTF-8
text.force_encoding('ISO-8859-1').encode('UTF-8') if original_encoding == 'ISO-8859-1' || original_encoding == 'windows-1252'
# For Windows-1252 or ISO-8859-1, force the encoding and convert to UTF-8
# text.force_encoding('ISO-8859-1').encode('UTF-8')
text.force_encoding(original_encoding).encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
else else
# Try to convert from detected encoding to UTF-8 # Try to convert from detected encoding to UTF-8
text.encode('UTF-8', original_encoding, invalid: :replace, undef: :replace, replace: '?') text.encode('UTF-8', original_encoding, invalid: :replace, undef: :replace, replace: '?')