Commit 74f1ee6824f7d2cb08aa7bff3c00f6b69014a00d
1 parent
5ebd5e2c
Exists in
master
and in
20 other branches
rails4: port translation tasks to Ruby-GetText 3.x
- updatepo has been replaced by gettext:po:update - makemo has been replaced by gettext:mo:update
Showing
2 changed files
with
42 additions
and
77 deletions
Show diff stats
lib/tasks/gettext.rake
... | ... | @@ -4,37 +4,21 @@ |
4 | 4 | |
5 | 5 | require 'pathname' |
6 | 6 | |
7 | -makemo_stamp = 'tmp/makemo.stamp' | |
8 | -desc "Create mo-files for L10n" | |
9 | -task :makemo => makemo_stamp | |
10 | -file makemo_stamp => Dir.glob('po/*/noosfero.po') do | |
11 | - Rake::Task['symlinkmo'].invoke | |
12 | - | |
13 | - require 'gettext' | |
14 | - require 'gettext/tools' | |
15 | - GetText.create_mofiles( | |
16 | - verbose: true, | |
17 | - po_root: 'po', | |
18 | - mo_root: 'locale', | |
19 | - ) | |
20 | - | |
21 | - Dir.glob('plugins/*').each do |plugindir| | |
22 | - GetText.create_mofiles( | |
23 | - verbose: true, | |
24 | - po_root: File.join(plugindir, 'po'), | |
25 | - mo_root: File.join(plugindir, 'locale'), | |
26 | - ) | |
27 | - end | |
28 | - | |
29 | - FileUtils.mkdir_p 'tmp' | |
30 | - FileUtils.touch makemo_stamp | |
31 | -end | |
32 | - | |
33 | -task :cleanmo do | |
34 | - rm_f makemo_stamp | |
7 | +require 'gettext/tools/task' | |
8 | +GetText::Tools::Task.define do |task| | |
9 | + task.domain = 'noosfero' | |
10 | + task.enable_po = true | |
11 | + task.po_base_directory = 'po' | |
12 | + task.mo_base_directory = 'locale' | |
13 | + task.files = [ | |
14 | + "{app,lib}/**/*.{rb,rhtml,erb}", | |
15 | + 'config/initializers/*.rb', | |
16 | + 'public/*.html.erb', | |
17 | + 'public/designs/themes/{base,noosfero,profile-base}/*.{rhtml,html.erb}', | |
18 | + ].map { |pattern| Dir.glob(pattern) }.flatten | |
35 | 19 | end |
36 | -task :clean => 'cleanmo' | |
37 | 20 | |
21 | +task 'gettext:mo:update' => :symlinkmo | |
38 | 22 | task :symlinkmo do |
39 | 23 | langmap = { |
40 | 24 | 'pt' => 'pt_BR', |
... | ... | @@ -55,57 +39,38 @@ task :symlinkmo do |
55 | 39 | end |
56 | 40 | end |
57 | 41 | |
58 | -desc "Update pot/po files to match new version." | |
59 | -task :updatepo do | |
60 | - | |
61 | - puts 'Extracting strings from source. This may take a while ...' | |
62 | - | |
63 | - # XXX this list is duplicated in test/unit/i18n_test.rb; if you change it | |
64 | - # here, please also update it there. | |
65 | - files_to_translate = [ | |
66 | - "{app,lib}/**/*.{rb,rhtml,erb}", | |
67 | - 'config/initializers/*.rb', | |
68 | - 'public/*.html.erb', | |
69 | - 'public/designs/themes/{base,noosfero,profile-base}/*.{rhtml,html.erb}', | |
70 | - ].map { |pattern| Dir.glob(pattern) }.flatten | |
71 | - | |
72 | - require 'gettext' | |
73 | - require 'gettext/tools' | |
74 | - GetText.update_pofiles( | |
75 | - 'noosfero', | |
76 | - files_to_translate, | |
77 | - Noosfero::VERSION, | |
78 | - { | |
79 | - po_root: 'po', | |
80 | - } | |
81 | - ) | |
82 | -end | |
83 | - | |
84 | 42 | Dir.glob('plugins/*').each do |plugindir| |
85 | 43 | plugin = File.basename(plugindir) |
86 | - task :updatepo => "updatepo:plugin:#{plugin}" | |
44 | + po_root = File.join(plugindir, 'po') | |
45 | + next if Dir["#{po_root}/**/*.po"].empty? | |
46 | + | |
47 | + namespace "noosfero:plugin:#{plugin}" do | |
48 | + GetText::Tools::Task.define do |task| | |
49 | + task.domain = plugin | |
50 | + task.enable_po = true | |
51 | + task.po_base_directory = po_root | |
52 | + task.mo_base_directory = File.join(plugindir, 'locale') | |
53 | + task.files = Dir["#{plugindir}/**/*.{rb,html.erb}"] | |
54 | + end | |
55 | + | |
56 | + task "gettext:po:cleanup" do | |
57 | + plugin_pot = File.join(po_root, plugin + '.pot') | |
58 | + if File.exists?(plugin_pot) && system("LANG=C msgfmt --statistics --output /dev/null #{plugin_pot} 2>&1 | grep -q '^0 translated messages.$'") | |
59 | + rm_f plugin_pot | |
60 | + end | |
61 | + sh 'find', po_root, '-type', 'd', '-empty', '-delete' | |
62 | + end | |
87 | 63 | |
88 | - desc "Extract strings from #{plugin} plugin" | |
89 | - task "updatepo:plugin:#{plugin}" do | |
90 | - files = Dir.glob("#{plugindir}/**/*.{rb,html.erb}") | |
91 | - po_root = File.join(plugindir, 'po') | |
92 | - require 'gettext' | |
93 | - require 'gettext/tools' | |
94 | - GetText.update_pofiles( | |
95 | - plugin, | |
96 | - files, | |
97 | - Noosfero::VERSION, | |
98 | - { | |
99 | - po_root: po_root, | |
100 | - } | |
101 | - ) | |
102 | - plugin_pot = File.join(po_root, "#{plugin}.pot") | |
103 | - if File.exists?(plugin_pot) && system("LANG=C msgfmt --statistics --output /dev/null #{plugin_pot} 2>&1 | grep -q '^0 translated messages.$'") | |
104 | - rm_f plugin_pot | |
64 | + task "gettext:po:update" do | |
65 | + Rake::Task["noosfero:plugin:#{plugin}:gettext:po:cleanup"].invoke | |
66 | + end | |
67 | + task "gettext:mo:update" do | |
68 | + Rake::Task["noosfero:plugin:#{plugin}:gettext:po:cleanup"].invoke | |
105 | 69 | end |
106 | - sh 'find', po_root, '-type', 'd', '-empty', '-delete' | |
107 | - puts | |
108 | 70 | end |
71 | + | |
72 | + task 'gettext:po:update' => "noosfero:plugin:#{plugin}:gettext:po:update" | |
73 | + task 'gettext:mo:update' => "noosfero:plugin:#{plugin}:gettext:mo:update" | |
109 | 74 | end |
110 | 75 | |
111 | 76 | def checkpo(po_files) | ... | ... |
lib/tasks/translation.rake
... | ... | @@ -2,10 +2,10 @@ namespace :noosfero do |
2 | 2 | namespace :translations do |
3 | 3 | |
4 | 4 | desc 'Update all translation files' |
5 | - task :update => ['updatepo', 'noosfero:doc:rebuild'] | |
5 | + task :update => ['gettext:po:update', 'noosfero:doc:rebuild'] | |
6 | 6 | |
7 | 7 | desc 'Compiles all translations' |
8 | - task :compile => ['makemo', 'noosfero:doc:translate'] | |
8 | + task :compile => ['gettext:mo:update', 'noosfero:doc:translate'] | |
9 | 9 | |
10 | 10 | end |
11 | 11 | end | ... | ... |