Created
February 15, 2022 18:24
-
-
Save LinkSake/216fae15a46c9ff7f4e20ba8cbfa8543 to your computer and use it in GitHub Desktop.
Localizable.strings to Localizable.swift Ruby Script
This file contains hidden or 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
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