commit c2f9dd871aeff90135d85c2fa43ce6ad62e35e30
Author: Marc Dequènes (Duck) <Duck@DuckCorp.org>
Date:   Wed Mar 9 01:06:24 2011 +0100

    [evol] I18n: new helpers to setup gettext domains and deferred translations (and one to inject the correct domain into specific core classes in order to be able to use cyborg-local translations into them (currently only needed for DSL classes))

diff --git a/IDEAS b/IDEAS
index 002a2e7..cd21278 100644
--- a/IDEAS
+++ b/IDEAS
@@ -1,4 +1,8 @@
 
+misc:
+  - rename schedule_task to schedule_job, as the <task> argument is not a DSL::Task
+    or transform it into a real task
+
 all bots:
   - API:
     * list manipulators:
diff --git a/bin/clerk b/bin/clerk
index 706b218..b949e63 100755
--- a/bin/clerk
+++ b/bin/clerk
@@ -25,18 +25,13 @@ require 'cyborghood/cyborg'
 
 
 module CyborgHood
-  module DSL
-    include I18nTranslation
-    bindtextdomain("cyborghood_clerk", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
-  end
   module ClerkLand
-    include I18nTranslation
-    bindtextdomain("cyborghood_clerk", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
-
     class Clerk < Cyborg
       # load config before modules are included
       Config.load(self.human_name)
 
+      inject_deferred_translations
+
       include BotNet
 
       def setup
diff --git a/bin/librarian b/bin/librarian
index 2bd6c12..e62368f 100755
--- a/bin/librarian
+++ b/bin/librarian
@@ -26,13 +26,12 @@ require 'cyborghood/cyborg'
 
 module CyborgHood
   module LibrarianLand
-    include I18nTranslation
-    bindtextdomain("cyborghood_librarian", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
-
     class Librarian < Cyborg
       # load config before modules are included
       Config.load(self.human_name)
 
+      inject_deferred_translations
+
       include BotNet
 
       def setup
diff --git a/bin/mapmaker b/bin/mapmaker
index 194f1a2..5d72b26 100755
--- a/bin/mapmaker
+++ b/bin/mapmaker
@@ -40,13 +40,12 @@ module CyborgHood
   end
 
   module MapMakerLand
-    include I18nTranslation
-    bindtextdomain("cyborghood_mapmaker", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
-
     class MapMaker < Cyborg
       # load config before modules are included
       Config.load(self.human_name)
 
+      inject_deferred_translations
+
       include BotNet
 
       def setup
diff --git a/bin/postman b/bin/postman
index a1830f7..e84cde9 100755
--- a/bin/postman
+++ b/bin/postman
@@ -28,13 +28,12 @@ require 'cyborghood-postman/mail_order'
 
 module CyborgHood
   module PostmanLand
-    include I18nTranslation
-    bindtextdomain("cyborghood_postman", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
-
     class Postman < Cyborg
       # load config before modules are included
       Config.load(self.human_name)
 
+      inject_deferred_translations
+
       include BotNet
 
       def setup
diff --git a/bin/test_client b/bin/test_client
index 47a0016..6821b3c 100755
--- a/bin/test_client
+++ b/bin/test_client
@@ -26,13 +26,14 @@ require 'cyborghood/cyborg'
 
 module CyborgHood
   module TestClientHome
-    include I18nTranslation
-    bindtextdomain("cyborghood_mapmaker", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
+    add_translations 'testclient'
 
     class TestClientClient < Cyborg
       # load config before modules are included
       Config.load
 
+      inject_deferred_translations
+
       include BotNet
 
       def start_work
diff --git a/lib/cyborghood-clerk/land.rb b/lib/cyborghood-clerk/land.rb
index 1d08be5..b28a7cd 100644
--- a/lib/cyborghood-clerk/land.rb
+++ b/lib/cyborghood-clerk/land.rb
@@ -19,6 +19,8 @@
 
 module CyborgHood
   module ClerkLand
+    add_deferred_translations 'clerk'
+
     def register_services(container)
       container.namespace_define(:clerk_land) do |b|
         b.records do
diff --git a/lib/cyborghood-librarian/land.rb b/lib/cyborghood-librarian/land.rb
index 8eba6f1..659ae9a 100644
--- a/lib/cyborghood-librarian/land.rb
+++ b/lib/cyborghood-librarian/land.rb
@@ -21,6 +21,8 @@ require 'active_ldap'
 
 module CyborgHood
   module LibrarianLand
+    add_deferred_translations 'librarian'
+
     def register_services(container)
       container.namespace_define(:librarian_land) do |b|
         b.records do
diff --git a/lib/cyborghood-mapmaker/land.rb b/lib/cyborghood-mapmaker/land.rb
index b30e834..9a49400 100644
--- a/lib/cyborghood-mapmaker/land.rb
+++ b/lib/cyborghood-mapmaker/land.rb
@@ -22,6 +22,8 @@ ENV['PATH'] = (ENV['PATH'].split(":") + ["/sbin", "/usr/sbin", "/usr/local/sbin"
 
 module CyborgHood
   module MapMakerLand
+    add_deferred_translations 'mapmaker'
+
     def register_services(container)
       container.namespace_define(:mapmaker_land) do |b|
         b.dns do
diff --git a/lib/cyborghood-postman/land.rb b/lib/cyborghood-postman/land.rb
index 87e4396..678439f 100644
--- a/lib/cyborghood-postman/land.rb
+++ b/lib/cyborghood-postman/land.rb
@@ -22,6 +22,8 @@ ENV['PATH'] = (ENV['PATH'].split(":") + ["/sbin", "/usr/sbin", "/usr/local/sbin"
 
 module CyborgHood
   module PostmanLand
+    add_deferred_translations 'postman'
+
     def register_services(container)
       container.namespace_define(:postman_land) do |b|
         b.imap do
diff --git a/lib/cyborghood.rb b/lib/cyborghood.rb
index f902d57..db02f44 100644
--- a/lib/cyborghood.rb
+++ b/lib/cyborghood.rb
@@ -28,10 +28,10 @@ require 'cyborghood/base/language'
 require 'cyborghood/base/exceptions'
 
 
+ENV['LC_ALL'] = "C"
+
 module CyborgHood
-  include I18nTranslation
-  ENV['LC_ALL'] = "C"
-  bindtextdomain("cyborghood", {:path => Config::L10N_DIR, :output_charset => "UTF-8"})
+  add_deferred_translations
 
   def register_services(container)
     container.define do |b|
diff --git a/lib/cyborghood/base/language.rb b/lib/cyborghood/base/language.rb
index 540ece4..f0ff0ee 100644
--- a/lib/cyborghood/base/language.rb
+++ b/lib/cyborghood/base/language.rb
@@ -21,6 +21,30 @@ require 'gettext'
 require 'http_headers'
 
 
+# helpers
+class Module
+  include GetText
+
+  @@ch_translations = Set.new
+
+  def add_translations(domain)
+    if @@ch_translations.include? domain
+      textdomain(domain)
+    else
+      bindtextdomain(domain, {:path => CyborgHood::Config::L10N_DIR, :output_charset => "UTF-8"})
+      @@ch_translations << domain
+    end
+  end
+
+  def add_deferred_translations(cyborg_model = nil)
+    domain = 'cyborghood'
+    domain += '_' + cyborg_model if cyborg_model
+    add_translations(domain)
+
+    include CyborgHood::I18nTranslation
+  end
+end
+
 module CyborgHood
   class I18nController
     include Singleton
diff --git a/lib/cyborghood/cyborg.rb b/lib/cyborghood/cyborg.rb
index 696e34b..14be593 100644
--- a/lib/cyborghood/cyborg.rb
+++ b/lib/cyborghood/cyborg.rb
@@ -77,6 +77,10 @@ module CyborgHood
       self.class.model
     end
 
+    def self.inject_deferred_translations
+      DSL.add_deferred_translations self.model.downcase
+    end
+
     # #^.*/system$# categories are reserved
     # but you may enhance or break the system as you wish
     def get_channel(name)
