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
70
|
# web/lib/ui/taginfo.rb
class Taginfo < Sinatra::Base
def i18n_walk(line, level, path, en, other)
out = ''
en.keys.sort.each do |key|
name = path.sub(/^\./, '') + '.' + key
name.sub!(/^\./, '')
if en[key].class == Hash
if other.nil?
out += line.call(level, "<b>#{key}</b>", name, '', '<span style="color: red;">MISSING</span>')
else
out += line.call(level, "<b>#{key}</b>", name, '', '')
out += i18n_walk(line, level+1, path + '.' + key, en[key], other[key])
end
else
if other.nil?|| ! other[key]
out += line.call(level, key, name, en[key], '<span style="color: red;">MISSING</span>')
else
out += line.call(level, key, name, en[key], other[key])
end
end
end
out
end
get '/taginfo' do
erb :'taginfo/index'
end
get '/taginfo/status' do
content_type 'text/plain'
age_in_days = DateTime.now() - DateTime.parse(@data_until)
if age_in_days.to_f > 1.5
halt 400, "data_too_old\n"
else
return "ok\n"
end
end
get '/taginfo/i18n' do
@title = 'Translations of taginfo texts'
@section = 'taginfo'
@section_title = t.taginfo.meta
@lang = params[:lang] || 'de'
@i18n_en = YAML.load_file("i18n/en.yml")
begin
@i18n_lang = YAML.load_file("i18n/#{@lang}.yml")
rescue
@error = "Unknown language: #{@lang}"
end
c = 'even'
@line = lambda { |level, key, name, en, other|
c = (c == '') ? 'even': ''
"<tr><td class='#{c}' style='padding-left: #{ level * 16 + 6 }px;'><span title='#{ name }'>#{ key }</span></td><td class='#{c}'>#{ en }</td><td class='#{c}'>#{ other }</td></tr>"
}
javascript "#{ r18n.locale.code }/taginfo/i18n"
erb :'taginfo/i18n'
end
get '/taginfo/apidoc' do
@title = t.taginfo.apidoc
@section = 'taginfo'
@section_title = t.taginfo.meta
erb :'taginfo/apidoc'
end
end
|