Created
October 9, 2018 15:54
-
-
Save xnt/055857779b60e7285130cc15d1a6d05d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Unsophisticated but useful way of replacing spanish language characters on a bunch of html files | |
REPLACE_CHARACTERS = { | |
"á" => "á", | |
"é" => "é", | |
"í" => "í", | |
"ó" => "ó", | |
"ú" => "ú", | |
"Á" => "Á", | |
"É" => "É", | |
"Í" => "Í", | |
"Ó" => "Ó", | |
"Ú" => "Ú", | |
"¿" => "¿", | |
"¡" => "¡", | |
"ñ" => "ntilde;", | |
"Ñ" => "Ntilde;", | |
} | |
file_names = Dir["*.html"] | |
file_names.each do |file_name| | |
puts file_name | |
text = File.read(file_name) | |
new_contents = text | |
REPLACE_CHARACTERS.each do |hash_key, hash_value| | |
new_contents = text.gsub "#{hash_key}", "#{hash_value}" | |
text = new_contents | |
end | |
File.open(file_name, "w") { |file| file.puts new_contents} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment