[Groonga-commit] droonga/droonga.org at e3b4db1 [gh-pages] task: move notice insertion code to Rakefile

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Feb 23 23:37:08 JST 2014


Kouhei Sutou	2014-02-23 23:37:08 +0900 (Sun, 23 Feb 2014)

  New Revision: e3b4db1bb9ec99f2872d2bb6925c3ae02ab08c8c
  https://github.com/droonga/droonga.org/commit/e3b4db1bb9ec99f2872d2bb6925c3ae02ab08c8c

  Message:
    task: move notice insertion code to Rakefile
    
    Because it is not general code.

  Modified files:
    Rakefile
    _tasks/i18n.rb

  Modified: Rakefile (+16 -0)
===================================================================
--- Rakefile    2014-02-23 23:26:16 +0900 (015c711)
+++ Rakefile    2014-02-23 23:37:08 +0900 (8177e46)
@@ -28,6 +28,22 @@ I18nTask.define do |task|
   task.locales.each do |locale|
     task.files -= Rake::FileList["#{locale}/**/*.md"]
   end
+  task.custom_translator = lambda do |original, translated, path|
+    notice = "{% comment %}\n" +
+               "##############################################\n" +
+               "  THIS FILE IS AUTOMATICALLY GENERATED FROM\n" +
+               "  \"#{path.po_file}\"\n" +
+               "  DO NOT EDIT THIS FILE MANUALLY!\n" +
+               "##############################################\n" +
+               "{% endcomment %}"
+    if /^---+$/ =~ translated
+      translated = translated.split(/^---+\n/)
+      translated[2] = "\n#{notice}\n\n#{translated[2]}"
+      translated.join("---\n")
+    else
+      "\n#{notice}\n\n#{translated}"
+    end
+  end
 end
 
 task :default => "i18n:translate"

  Modified: _tasks/i18n.rb (+4 -13)
===================================================================
--- _tasks/i18n.rb    2014-02-23 23:26:16 +0900 (60e608f)
+++ _tasks/i18n.rb    2014-02-23 23:37:08 +0900 (21c34af)
@@ -34,6 +34,7 @@ class I18nTask
   attr_accessor :files
   attr_accessor :translator_name
   attr_accessor :translator_email
+  attr_accessor :custom_translator
   def initialize
     @po_dir_path = Pathname.new("_po")
     @base_dir_path = Pathname.new(".")
@@ -42,6 +43,7 @@ class I18nTask
     @translator_name = nil
     @translator_email = nil
     @yard_locales = {}
+    @custom_translator = nil
   end
 
   def define
@@ -221,19 +223,8 @@ class I18nTask
   def translate(input, locale, path)
     text = YARD::I18n::Text.new(input)
     translated_text = text.translate(yard_locale(locale))
-    notice = "{% comment %}\n" +
-               "##############################################\n" +
-               "  THIS FILE IS AUTOMATICALLY GENERATED FROM\n" +
-               "  \"#{path.po_file}\"\n" +
-               "  DO NOT EDIT THIS FILE MANUALLY!\n" +
-               "##############################################\n" +
-               "{% endcomment %}"
-    if /^---+$/ =~ translated_text
-      translated_text = translated_text.split(/^---+\n/)
-      translated_text[2] = "\n#{notice}\n\n#{translated_text[2]}"
-      translated_text = translated_text.join("---\n")
-    else
-      translated_text = "\n#{notice}\n\n#{translated_text}"
+    if @custom_translator
+      translated_text = @custom_translator.call(input, translated_text, path)
     end
     translated_text
   end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index