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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
#!/usr/bin/env ruby
raise 'Please, use ruby1.9.3 or later.' if RUBY_VERSION < '1.9.3'
=begin
Common Rakefile, Rantfile to place sisu markup translation under
po4a management softlink Rakefile and Rantfile to this file
* Homepage: <http://www.jus.uio.no/sisu/SiSU>
<http://sisudoc.org>
* Download: <http://www.jus.uio.no/sisu/download>
Copyright (C) 2013 Ralph Amissah
* License: LGPL - GNU Lesser General Public License
[same license as Rant provided within the Rant package]
* Ralph Amissah <ralph@amissah.com>
Ralph Amissah <ralph.amissah@gmail.com>
Rake is a Ruby build program by Jim Weirich
* Rake may be downloaded and installed from:
<http://rake.rubyforge.org/>
Rant is a Ruby build program by Stefan Lang
* Rant may be downloaded and installed from:
<http://make.rubyforge.org/>
Notes on use:
rake -T
[if rant is preferred and installed]
rant -T
=end
require 'find'
require 'fileutils'
#require 'ftools'
require 'rbconfig.rb'
#include RbConfig
require 'yaml'
include FileUtils
def project_details
def name
'SiSU translations under po4a management'
end
def name_warning
<<-WOK
#{name}
WARNING all sisu markup files (.ssm, .sst, .ssi) in languages other than #{language.source}
are managed by po4a, through translations of the source language to other languages.
#{language.info_on_selection}
WOK
end
def rake_project
"Rakefile for placing #{name}"
end
self
end
def query
def answer?(ask)
resp='redo'
print ask + %{ ['yes', 'no' or 'quit']: }
resp=File.new('/dev/tty').gets.strip
if resp == 'yes'; true
elsif resp == 'no'; false
elsif resp =~/^quit|exit$/; exit
else
puts %{[please type: 'yes', 'no' or 'quit']}
answer?(ask)
end
end
self
end
def notice
def warn_and_proceed?
%{WARNING: This Software is used entirely at your own risk.
PROCEED?}
end
def default(selection=nil)
ans= if selection
case selection
when selection.is_a?(String)
<<-WOK
#{project_details.rake_project}
Information on alternative actions is available using: "rake help" or "rake -T"
Default action selected - "#{selection} #{project_details.name}"
#{warn_and_proceed?}
WOK
when :make
<<-WOK
#{project_details.rake_project}
Information on alternative actions is available using: "rake help" or "rake -T"
#{selection.upcase} selected - #{selection} #{project_details.name}
WARNING: this action assumes (and places) this project is under po4a
(translation) management. It will create the sub-directories:
#{language.translations_available_str}
& file: #{filename.po4a_cfg}
in the current directory:
#{Dir.pwd}
It will populate the sub-directories with translation files created from
the pot and po files found under the corresponding language sub-directories,
(under #{dir.pot}/ & #{dir.po}/). (OVERWRITING any existing translated
.ssm .sst .ssi files in language subdirectories that are not under po4a
management).
#{warn_and_proceed?}
WOK
when :clean
<<-WOK
#{project_details.rake_project}
Information on alternative actions is available using: "rake help" or "rake -T"
#{selection.upcase} selected - #{selection} #{project_details.name}
#{warn_and_proceed?}
WOK
when :distclean
<<-WOK
#{project_details.rake_project}
Information on alternative actions is available using: "rake help" or "rake -T"
#{selection.upcase} selected - #{selection} #{project_details.name}
WARNING: this action assumes (and places) this project is under po4a
(translation) management. It will remove the sub-directories:
#{language.translations_available_str}
& file: #{filename.po4a_cfg}
in the current directory:
#{Dir.pwd}
Note: these sub-directories & the config file #{filename.po4a_cfg}
should be auto-generated from pot and po files if this project translation
is under po4a management.
This query is to give you the chance to make sure you know what you are doing.
#{warn_and_proceed?}
WOK
when :rebuild
<<-WOK
#{project_details.rake_project}
Information on alternative actions is available using: "rake help" or "rake -T"
#{selection.upcase} selected - #{selection} #{project_details.name}
WARNING: this action assumes (and places) this project is under po4a
(translation) management. It will destroy/clobber and then create again the
sub-directories:
#{language.translations_available_str}
populating them with translation files created from the pot and po files
found under the corresponding language sub-directories in (#{dir.pot}/
& #{dir.po}/).
It will also generate the file: #{filename.po4a_cfg}
These actions will be taken in the current directory:
#{Dir.pwd}
This query is to give you the chance to make sure you know what you are doing.
#{warn_and_proceed?}
WOK
else
<<-WOK
#{project_details.rake_project}
Information on alternative actions is available using: "rake help" or "rake -T"
Default action selected - "#{selection} #{project_details.name}"
#{warn_and_proceed?}
WOK
end
else
<<-WOK
#{project_details.rake_project}
Information on alternative actions is available using: "rake help" or "rake -T"
Default action selected - "install and to setup #{project_details.name}"
#{warn_and_proceed?}
WOK
end
resp=query.answer?(ans)
exit unless resp
end
def project_help
puts <<-WOK
#{project_details.name}
#{project_details.rake_project}
This rake file is to assist with having sisu markup files under po4a
translation management. It assumes that the source language files are placed
under the sub-directory identifying the source language set, which is currently
#{language.source}
The files there are used to make the source translation file in the directory #{dir.pot}/
Which is then used to create files for translation under the directory #{dir.po}/
in sub-directories bearing the translation languages ISO code.
The current language translation selection is: #{translations_selected_str}
The languages selected are located in the file: #{filename.languages}
sisu available language list: #{sisu_available_str}
For a more detailed and up to date task list use:
rake -T
WOK
end
self
end
def tasks
system('rake -T')
end
def filename
def languages
'translation_languages'
end
def po4a_cfg
'po4a.cfg'
end
self
end
def dir
def pwd
Dir.pwd
end
def po4a_
'po4a/' # ''
end
def pot
po4a_ + 'pot'
end
def po
po4a_ + 'po'
end
self
end
def dir_mk(dir)
FileUtils::mkdir_p(dir) unless FileTest.directory?(dir)
end
def po4a_flags
def debug
'-d -v'
end
def normal
''
end
def quiet
'-q'
end
self
end
def language
def source #source_language
'en'
end
def translations_selected #translation_languages
IO.read(filename.languages, mode: 'r:utf-8').split(/\s+/)
end
def translations_available
translations_selected & sisu_available
end
def info_on_selection
if translations_selected != translations_available
<<-WOK
WARNING: language selections mismatch
The current language translation selection appears to be: #{translations_selected_str}
Of which the following are valid (available) selections: #{translations_available_str}
sisu available language list: #{sisu_available_str}
the following will be used: #{translations_available_str}
The languages selected are located in the file: #{filename.languages}
WOK
else
<<-WOK
The current language translation selection is: #{translations_selected_str}
The languages selected are located in the file: #{filename.languages}
sisu available language list: #{sisu_available_str}
WOK
end
end
def sisu_available
%w[am bg bn br ca cs cy da de el en eo es et eu fi fr ga gl he hi hr hy ia is it ja ko la lo lt lv ml mr nl nn no oc pl pt pt_BR ro ru sa se sk sl sq sr sv ta te th tk tr uk ur us vi zh]
end
def translations_selected_str
language.translations_selected.join(' ')
end
def translations_available_str
language.translations_available.join(' ')
end
def sisu_available_str
language.sisu_available.join(' ')
end
self
end
def files_src
def ssm
Dir.glob("#{language.source}/*.ssm").sort
end
def sst
Dir.glob("#{language.source}/*.sst").sort
end
def ssi
Dir.glob("#{language.source}/*.ssi").sort
end
def all
Dir.glob("#{language.source}/*{.ssm,.sst,.ssi}").sort
end
self
end
def po4a_cfg_file
File.open("#{Dir.pwd}/#{filename.po4a_cfg}",'w')
end
def po4a
def configure #po4a_cfg
po4a_cfg_arr=[]
po4a_cfg_arr << "[po4a_langs] #{language.translations_available_str}"
po4a_cfg_arr << "[po4a_paths] #{dir.pot}/$master.pot $lang:#{dir.po}/$lang/$master.po"
files_src.ssm.each do |file_src|
file_src_fn=file_src.gsub(/#{language.source}\//,'')
po4a_cfg_arr << "[type: text] #{file_src} $lang:$lang/#{file_src_fn}"
end
files_src.sst.each do |file_src|
file_src_fn=file_src.gsub(/#{language.source}\//,'')
po4a_cfg_arr << "[type: text] #{file_src} $lang:$lang/#{file_src_fn}"
end
files_src.ssi.each do |file_src|
file_src_fn=file_src.gsub(/#{language.source}\//,'')
po4a_cfg_arr << "[type: text] #{file_src} $lang:$lang/#{file_src_fn}"
end
file=po4a_cfg_file
po4a_cfg_arr.each do |txt|
puts txt
file << txt << "\n"
end
file.close
system("po4a --keep 0 --no-backups --package-name sisu-manual #{po4a_flags.normal} #{filename.po4a_cfg}")
end
self
end
def project
dir_mk(dir.pot)
language.translations_available.each do |lang_dir|
dir_lang="#{Dir.pwd}/#{dir.po}/#{lang_dir}"
dir_mk(dir_lang)
end
po4a.configure
end
def clean
#rm -rf ../build
FileUtils.rm_f Dir.glob("#{dir.po}/*/*.po~")
end
def distclean
FileUtils::rm_f(filename.po4a_cfg)
FileUtils::rm_r(language.translations_available,:force => true)
end
#% task lists
desc "runs make (see its description below)"
task :default => [:make]
desc "assist with having sisu markup files managed by po4a
create configuration files, and language directories and
populate them with po4a pot & po files for translation and
from those (as translated) create translated sisu markup
.ssm .sst & .ssi files in corresponding language sub-directories"
task :make => [:notice_make_,:build_]
desc "help"
task :help => [:project_help_,:tasks_]
desc "clean temporary files"
task :clean => [:notice_clean_,:clean_]
desc "removes auto-generated files under po4a management
including translated .ssm .sst & .ssi files,
that are created from po4a pot and po files"
task :distclean => [:notice_distclean_,:distclean_]
desc "runs 'distclean' and 'make' (see their descriptions above)"
task :rebuild => [:notice_rebuild_,:distclean_,:build_]
if File.directory?(dir.pot) \
and File.directory?(dir.po)
#desc ""
task :clean! => [:clean_]
task :distclean! => [:distclean_]
task :rebuild! => [:distclean_,:build_]
task :make! => [:build_]
else
task :make! => [:build_]
end
#% task actions
task :project_help_ do
notice.project_help
end
task :tasks_ do
tasks
end
task :build_ do
project
end
task :clean_ do
clean
end
task :distclean_ do
distclean
end
task :notice_default_ do
notice.default
end
task :notice_make_ do
notice.default(:make)
end
task :notice_clean_ do
notice.default(:clean)
end
task :notice_distclean_ do
notice.default(:distclean)
end
task :notice_rebuild_ do
notice.default(:rebuild)
end
__END__
|