forked from hivewallet/hive-mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reuse_translation.rb
executable file
·37 lines (28 loc) · 1.21 KB
/
reuse_translation.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env ruby
if ARGV.length < 3
puts "#{$PROGRAM_NAME} <source_filename> <source_title> <target_filename> [<target_title>]"
exit 1
end
source_filename, source_title, target_filename, target_title = ARGV
target_title ||= source_title
langs = Dir['Hive/*.lproj'].map { |path| File.basename(path) }.reject { |dir| dir == 'en.lproj' }
langs.each do |lang|
source_file = if File.exist?("Hive/#{lang}/#{source_filename}")
"Hive/#{lang}/#{source_filename}"
elsif File.exist?("Hive/Controllers/#{lang}/#{source_filename}")
"Hive/Controllers/#{lang}/#{source_filename}"
end
target_file = if File.exist?("Hive/#{lang}/#{target_filename}")
"Hive/#{lang}/#{target_filename}"
elsif File.exist?("Hive/Controllers/#{lang}/#{target_filename}")
"Hive/Controllers/#{lang}/#{target_filename}"
end
next unless source_file && target_file
source = File.read(source_file)
target = File.read(target_file)
source_line = source.lines.map(&:strip).detect { |l| l.start_with?(%("#{source_title}")) }
next unless source_line
translation = source_line.scan(/"(.*?)"/)[1][0]
target = target.gsub(/"#{target_title}" = ".*?";/, %("#{target_title}" = "#{translation}";))
File.write(target_file, target)
end