-
Notifications
You must be signed in to change notification settings - Fork 1
/
decorators.rb
156 lines (139 loc) · 4.81 KB
/
decorators.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
class MediawikiDecorator
def MediawikiDecorator.factory item
case item[:type]
when :transifex
Transifex_MediawikiDecorator.new item
when :launchpad
Launchpad_MediawikiDecorator.new item
when :taginfo
Taginfo_MediawikiDecorator.new item, language: 'Pt-br' # or pt-br
when :translatewiki
Translatewiki_MediawikiDecorator.new item, language: 'pt-br'
when :weblate
Weblate_MediawikiDecorator.new item, language: 'pt'
when :github_yaml
Github_MediawikiDecorator.new item
else
MediawikiDecorator.new nil
end
end
def url_template
'%{project} %{language}' # never use this, extend it
end
def initialize(item, url: nil, language: 'pt_BR')
unless item == nil
if item[:language] == nil
item[:language] = language
end
@item = item
@url = url_template % item
else
@item = {}
@url = url
end
end
def decorate_message(msg)
if @url != nil
'[' + @url + ' ' + msg + ']'
else
msg
end
end
end
# https://translations.launchpad.net/keepright/trunk/+pots/keepright/pt_BR/+details
# https://translations.launchpad.net/keepright/trunk/+pots/keepright/pt_BR/+translate
class Launchpad_MediawikiDecorator < MediawikiDecorator
def url_template
if @item[:resource] == nil
'https://translations.launchpad.net/%{project}/trunk/+pots/%{project}/%{language}/+translate'
else
'https://translations.launchpad.net/%{project}/trunk/+pots/%{resource}/%{language}/+translate'
end
end
end
# https://hosted.weblate.org/projects/osmand/main
# https://hosted.weblate.org/projects/osmand/main/pt/translate/?type=untranslated
class Weblate_MediawikiDecorator < MediawikiDecorator
def url_template
'https://hosted.weblate.org/projects/%{project}/%{resource}/%{language}/translate/?type=untranslated'
end
end
# https://translatewiki.net/w/i.php?title=Special:Translate&action=proofread&group=out-osm-site&language=pt-br&filter=translated
class Translatewiki_MediawikiDecorator < MediawikiDecorator
def url_template
'https://translatewiki.net/w/i.php?title=Special:Translate&action=proofread&group=%{project}&language=%{language}&filter=translated'
end
end
class Transifex_MediawikiDecorator < MediawikiDecorator
def url_template
if @item[:resource] == nil
'https://www.transifex.com/projects/p/%{project}/language/%{language}/'
else
'https://www.transifex.com/projects/p/%{project}/viewstrings/#%{language}/%{resource}'
end
end
end
class Github_MediawikiDecorator < MediawikiDecorator
def url_template
'https://github.com/%{project}/blob/master/%{resource_dest}'
end
end
# http://stackoverflow.com/a/1251199
class SuperProxy
def initialize(obj)
@obj = obj
end
def method_missing(meth, *args, &blk)
@obj.class.superclass.instance_method(meth).bind(@obj).call(*args, &blk)
end
end
class Object
private
def sup
SuperProxy.new(self)
end
end
class Taginfo_MediawikiDecorator < MediawikiDecorator
def url_template; '' end
def decorate_message(msg)
for_keys = 'http://wiki.openstreetmap.org/wiki/Category:%{language}_key_descriptions'
for_tags = 'http://wiki.openstreetmap.org/wiki/Category:%{language}_tag_descriptions'
# 'keys 11.21% / tags 1.42%'
part = msg.split
@url = for_keys % @item
for_keys = sup.decorate_message part[1]
@url = for_tags % @item
for_tags = sup.decorate_message part[4]
'%s %s %s %s %s' % [part[0], for_keys, part[2], part[3], for_tags]
end
end
if caller.length == 0
item = { :project => 'taginfo.openstreetmap.org' }
decorator = Taginfo_MediawikiDecorator.new item, language: 'Pt-br'
puts decorator.decorate_message 'keys 11.21% / tags 1.42%'
exit
end
if caller.length == 0
item = { :project => 'out-osm-site' }
decorator = MediawikiDecorator.new item, language: 'pt-br'
puts decorator.decorate_message '100%'
#exit
end
if caller.length == 0
item = { :project => 'out-osm-site' }
decorator = Translatewiki_MediawikiDecorator.new item, language: 'pt-br'
puts decorator.decorate_message '100%'
#exit
end
if caller.length == 0
item = { :project => 'osmand', :resource => 'main' }
decorator = Weblate_MediawikiDecorator.new item, language: 'pt'
puts decorator.decorate_message '100%'
#exit
end
if caller.length == 0
item = { :project => 'keepright', :resource => 'keepright' }
decorator = Launchpad_MediawikiDecorator.new item
puts decorator.decorate_message '100%'
exit
end