-
Notifications
You must be signed in to change notification settings - Fork 1
/
schema-to-po.rb
69 lines (61 loc) · 1.46 KB
/
schema-to-po.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'json'
#src_file = ARGV[1]
#dst_file = ARGV[2]
class PoEntry
def initialize
@meta = ""
@text = ""
end
attr_accessor :meta
attr_accessor :text
end
src_file = "osc-schema.json"
dst_file = "zyn_translation-en.po"
output = File.open(dst_file, "w+")
json = File.read(src_file)
obj = JSON.parse(json)
strings = Hash.new
obj["parameter"].each do |x|
path = x["path"]
shortname = x["shortname"]
tooltip = x["tooltip"]
options = x["options"]
if(shortname)
tmp = strings[shortname]
tmp ||= PoEntry.new
tmp.text = shortname
tmp.meta << "#{path} shortname\n"
strings[shortname] = tmp
end
if(tooltip)
tmp = strings[tooltip]
tmp ||= PoEntry.new
tmp.text = tooltip
tmp.meta << "#{path} tooltip\n"
strings[tooltip] = tmp
end
if(options)
options.each do |o|
oo = o["value"]
tmp = strings[oo]
tmp ||= PoEntry.new
tmp.text = oo
tmp.meta << "#{path} option\n"
strings[oo] = tmp
end
end
#"shortname"
#"tooltip"
#"options" "value"
end
strings.keys.to_a.sort.each do |k|
po = strings[k]
po.meta.each_line do |l|
output.puts "#. #{l}"
end
output.puts "msgid #{po.text.inspect}"
output.puts 'msgstr ""'
output.puts ""
end
puts "[INFO] total translatable strings: #{strings.length}"
puts "Done..."