Skip to content

Instantly share code, notes, and snippets.

@iwan
Last active February 22, 2022 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwan/48a4e6e3a4a4f739124fde0dd7a3851f to your computer and use it in GitHub Desktop.
Save iwan/48a4e6e3a4a4f739124fde0dd7a3851f to your computer and use it in GitHub Desktop.
Update an outdated existing translation (here in italian) to a base file in english language
en_filename = "English.ini" # located in redcap/redcap_vxx.x.x/LanguageUpdater/ folder
it_filename = "Italian_v10_8_4 3.ini" # an existing but outdated file with translations
def read_file(filename)
hash = {}
count = 0
key = ""
value = ""
IO.readlines(filename, chomp: true).each do |line|
a = line.split(" = ")
# puts "#{count}: #{a.inspect}"
if a.size==2 && a[0][0]!=" "
key = a[0]
value = a[1]
else
value += a[0] unless a[0].nil?
end
if value[-1]=='"'
hash[key] = value
value = ""
end
count+=1
end
puts "read #{count} lines from file #{filename}"
hash
end
en_hash = read_file en_filename
it_hash = read_file it_filename
File.open("ita_new.txt", 'w') do |file|
en_hash.each_pair do |k, v|
file.write("#{k} = #{it_hash.fetch(k, v).gsub(/[ ]{2,}/, " ")}\r\n")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment