Skip to content

Instantly share code, notes, and snippets.

@xnt
Created October 9, 2018 15:54
Show Gist options
  • Save xnt/055857779b60e7285130cc15d1a6d05d to your computer and use it in GitHub Desktop.
Save xnt/055857779b60e7285130cc15d1a6d05d to your computer and use it in GitHub Desktop.
#!/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