-
Notifications
You must be signed in to change notification settings - Fork 14
/
Rakefile
110 lines (83 loc) · 2.42 KB
/
Rakefile
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
# frozen_string_literal: true
namespace :sources do
task extract: ['sphinx/bin/sphinx-build'] do
sh 'sphinx/bin/sphinx-build -b gettext . _build/gettext'
end
desc 'Update gettext and config from the source and push to transifex'
task update: %i[sources:extract tx:config tx:push]
end
namespace :translations do
desc 'Pull translations from transifex and commit'
task update: %i[tx:pull] do
sh 'git add locales/'
sh 'git commit -m "Update translations from transifex"'
puts 'You can now push the docs, so the website can be rebuilt.'
end
end
namespace :tx do
task push: ['bin/tx'] do
sh 'bin/tx push --source'
end
task pull: ['bin/tx'] do
sh 'bin/tx pull --translations --all --force'
end
task :config do
Rake::Task['.tx/config'].execute
end
task status: ['bin/tx'] do
sh 'bin/tx --version'
sh 'bin/tx status'
end
end
namespace :build do
task all: %i[en it fr]
task :en do
Rake::Task['build:docs'].execute(locale: 'en')
end
task :it do
Rake::Task['build:docs'].execute(locale: 'it')
end
task :fr do
Rake::Task['build:docs'].execute(locale: 'fr')
end
task :docs, [:locale] => ['sphinx/bin/sphinx-build'] do |_t, args|
locale = args[:locale]
sh "sphinx/bin/sphinx-build -b html -D language=#{locale} . _build/html/#{locale}"
end
end
directory 'bin/'
file 'bin/tx': ['bin/'] do
transifex_version = 'v1.6.4'
sh "curl -L https://github.com/transifex/cli/releases/download/#{transifex_version}/tx-linux-amd64.tar.gz | " \
'tar xz -C bin/'
end
directory '.tx/'
file '.tx/config': ['.tx/'] do |task|
organization = 'hitobito'
project = 'user_documentation'
source_lang = 'de'
header = <<~INI
[main]
host = https://www.transifex.com
INI
template = <<~INI
[o:#{organization}:p:#{project}:r:<resource>]
file_filter = locales/<lang>/LC_MESSAGES/<resource>.po
source_file = _build/gettext/<resource>.pot
source_lang = #{source_lang}
type = PO
INI
File.open(task.name, 'w') do |config|
config << header
FileList['_build/gettext/*.pot'].each do |source|
config << template.gsub('<resource>', File.basename(source, '.pot'))
end
end
end
directory 'sphinx/' do
sh 'virtualenv sphinx'
end
file 'sphinx/bin/sphinx-build': ['sphinx/'] do
sh 'sphinx/bin/pip install sphinx_rtd_theme' # ensure correct dependency resolution
sh 'sphinx/bin/pip install sphinx sphinx-intl[transifex]'
end