Commit 6686f090f4f8e77d0215e1825bb62f29f4c0c054

Authored by Antonio Terceiro
1 parent 7d06b77b

Support compiling translations without Rails environment

$ rake -f Rakefile.translations

The above invocation will work without a full rails environment, which
requires a config/database.yml, an actual database to connect to, plus
loading all the Rails stack which is painfully slow.

This can now be used by distribution packages to compile translations
during package build without worrying much.
Rakefile.translations 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +# This Rakefile is intentionally independent from Rails to it can be used to
  2 +# handle translations without having to load the entire Rails environment
  3 +# (which is slow, requires a database connection and several other
  4 +# inconveniences).
  5 +
  6 +$: << 'lib'
  7 +load 'lib/tasks/gettext.rake'
  8 +load 'lib/tasks/doc.rake'
  9 +load 'lib/tasks/translation.rake'
  10 +
  11 +task :default => 'noosfero:translations:compile'
... ...
lib/noosfero/version.rb
... ... @@ -3,6 +3,7 @@ module Noosfero
3 3 VERSION = '1.1~rc1'
4 4 end
5 5  
6   -if File.exist?(File.join(Rails.root, '.git'))
7   - Noosfero::VERSION.clear << Dir.chdir(Rails.root) { `git describe --tags`.strip }
  6 +root = File.expand_path(File.dirname(__FILE__) + '/../..')
  7 +if File.exist?(File.join(root, '.git'))
  8 + Noosfero::VERSION.clear << Dir.chdir(root) { `git describe --tags`.strip }
8 9 end
... ...
lib/tasks/doc.rake
  1 +require 'noosfero'
  2 +require 'pathname'
  3 +
1 4 namespace :noosfero do
2 5 namespace :doc do
3 6 def plugins_textiles
... ... @@ -9,8 +12,9 @@ namespace :noosfero do
9 12 end
10 13 end
11 14 task :unlink_plugins_textiles do
12   - rm_f Dir.glob(Rails.root.join('doc/noosfero/plugins/*.textile')) -
13   - [Rails.root.join('doc/noosfero/plugins/index.textile')]
  15 + root = Pathname.new(File.dirname(__FILE__) + '/../..').expand_path
  16 + rm_f Dir.glob(root.join('doc/noosfero/plugins/*.textile')) -
  17 + [root.join('doc/noosfero/plugins/index.textile')]
14 18 end
15 19 input = Dir.glob('doc/noosfero/**/*.textile') + plugins_textiles.map{|i| "doc/noosfero/plugins/#{File.basename(i)}"}
16 20 topics_xhtml = input.map { |item| item.sub('.textile', '.en.xhtml') }.uniq
... ...
lib/tasks/gettext.rake
... ... @@ -2,6 +2,8 @@
2 2 # Added for Ruby-GetText-Package
3 3 #
4 4  
  5 +require 'pathname'
  6 +
5 7 makemo_stamp = 'tmp/makemo.stamp'
6 8 desc "Create mo-files for L10n"
7 9 task :makemo => makemo_stamp
... ... @@ -37,14 +39,15 @@ task :symlinkmo do
37 39 langmap = {
38 40 'pt' => 'pt_BR',
39 41 }
40   - mkdir_p(Rails.root.join('locale'))
41   - Dir.glob(Rails.root.join('po/*/')).each do |dir|
  42 + root = Pathname.new(File.dirname(__FILE__) + '/../..').expand_path
  43 + mkdir_p(root.join('locale'))
  44 + Dir.glob(root.join('po/*/')).each do |dir|
42 45 lang = File.basename(dir)
43 46 orig_lang = langmap[lang] || lang
44   - mkdir_p(Rails.root.join('locale', "#{lang}", 'LC_MESSAGES'))
  47 + mkdir_p(root.join('locale', "#{lang}", 'LC_MESSAGES'))
45 48 ['iso_3166'].each do |domain|
46 49 origin = "/usr/share/locale/#{orig_lang}/LC_MESSAGES/#{domain}.mo"
47   - target = Rails.root.join('locale', "#{lang}", 'LC_MESSAGES', "#{domain}.mo")
  50 + target = root.join('locale', "#{lang}", 'LC_MESSAGES', "#{domain}.mo")
48 51 if !File.symlink?(target)
49 52 ln_s origin, target
50 53 end
... ...
lib/tasks/translation.rake
... ... @@ -5,7 +5,7 @@ namespace :noosfero do
5 5 task :update => ['updatepo', 'noosfero:doc:rebuild']
6 6  
7 7 desc 'Compiles all translations'
8   - task :compile => ['makemo', 'environment', 'noosfero:doc:translate']
  8 + task :compile => ['makemo', 'noosfero:doc:translate']
9 9  
10 10 end
11 11 end
... ...