Skip to content

Instantly share code, notes, and snippets.

@LinkSake
Created February 15, 2022 18:24
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 LinkSake/216fae15a46c9ff7f4e20ba8cbfa8543 to your computer and use it in GitHub Desktop.
Save LinkSake/216fae15a46c9ff7f4e20ba8cbfa8543 to your computer and use it in GitHub Desktop.
Localizable.strings to Localizable.swift Ruby Script
file = IO.read(ARGV[0])
keys = file.gsub(/=+\s("+.+")+;/, '')
values = file.gsub(/("+.+")+\s+=+\s/, '')
keys_arr = keys.split('"').select { |f| /[a-zA-Z]/.match(f) }
values_arr = values.split('"').select { |f| /[a-zA-Z]/.match(f) }
File.open(ARGV[1], 'w') do | f |
keys_arr.each_with_index do |key, index|
key.gsub!('.', '_')
f.puts '/// ' + values_arr[index]
f.puts 'static let ' + key + ': String = ' + '"' + values_arr[index] + '"'
f.puts ''
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment