gettext.rake
1.88 KB
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
#
# Added for Ruby-GetText-Package
#
makemo_stamp = 'tmp/makemo.stamp'
desc "Create mo-files for L10n"
task :makemo => makemo_stamp
file makemo_stamp => Dir.glob('po/*/noosfero.po') do
ruby '-rconfig/boot -e \'require "gettext"; require "gettext/utils"; GetText.create_mofiles(true, "po", "locale")\' 2>/dev/null'
Rake::Task['symlinkmo'].invoke
FileUtils.mkdir_p 'tmp'
FileUtils.touch makemo_stamp
end
task :cleanmo do
rm_f makemo_stamp
end
task :clean => 'cleanmo'
task :symlinkmo do
langmap = {
'pt' => 'pt_BR',
}
mkdir_p(File.join(Rails.root, 'locale'))
Dir.glob(File.join(Rails.root, 'locale/*')).each do |dir|
lang = File.basename(dir)
orig_lang = langmap[lang] || lang
mkdir_p("#{Rails.root}/locale/#{lang}/LC_MESSAGES")
['iso_3166'].each do |domain|
origin = "/usr/share/locale/#{orig_lang}/LC_MESSAGES/#{domain}.mo"
target = "#{Rails.root}/locale/#{lang}/LC_MESSAGES/#{domain}.mo"
if !File.symlink?(target)
ln_s origin, target
end
end
end
end
desc "Update pot/po files to match new version."
task :updatepo do
require 'gettext_rails/tools'
require_dependency 'noosfero'
GetText::RubyParser::ID << '__'
GetText::RubyParser::PLURAL_ID << 'n__'
GetText::ActiveRecordParser.init(:use_classname => false)
puts 'Extracting strings from source. This may take a while ...'
sources =
Dir.glob("{app,lib}/**/*.{rb,rhtml,erb}") +
Dir.glob('config/initializers/*.rb') +
Dir.glob('public/*.html.erb') +
Dir.glob('public/designs/themes/{base,noosfero,profile-base}/*.{rhtml,html.erb}') +
Dir.glob('plugins/**/{controllers,models,lib,views}/**/*.{rhtml,html.erb,rb}')
GetText.update_pofiles(Noosfero::PROJECT, sources, "#{Noosfero::PROJECT} #{Noosfero::VERSION}")
end
task :checkpo do
sh 'for po in po/*/noosfero.po; do echo -n "$po: "; msgfmt --statistics --output /dev/null $po; done'
end
# vim: ft=ruby