Skip to content

Commit

Permalink
i18n: support auto updating edit.po by updating .po from git pull
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 5, 2014
1 parent 00a7284 commit 5bd93ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
*.edit.po
*.edit.po~
*.pot
*.time_stamp
/_site/
/_po/*.po
20 changes: 19 additions & 1 deletion _tasks/i18n.rb
Expand Up @@ -48,6 +48,10 @@ def initialize

def define
namespace :i18n do
namespace :internal do
task :force
end

namespace :po do
namespace :edit do
define_edit_po_update_task
Expand Down Expand Up @@ -79,7 +83,9 @@ def define_edit_po_locale_update_task(locale)

po_dir = path.po_dir.to_s
directory po_dir
file edit_po_file => [target_file, po_dir] do
dependencies = [target_file, po_dir]
dependencies << "i18n:internal:force" if po_file_is_updated?(path)
file edit_po_file => dependencies do
relative_base_path = @base_dir_path.relative_path_from(path.po_dir)
generator = YARD::I18n::PotGenerator.new(relative_base_path.to_s)
yard_file = YARD::CodeObjects::ExtraFileObject.new(target_file)
Expand Down Expand Up @@ -126,6 +132,12 @@ def define_edit_po_locale_update_task(locale)
task :update => edit_po_files
end

def po_file_is_updated?(path)
return false unless path.po_file.exist?
return false unless path.time_stamp_file.exist?
path.po_file.mtime > path.time_stamp_file.mtime
end

def define_po_update_task
@locales.each do |locale|
namespace locale do
Expand All @@ -147,6 +159,7 @@ def define_po_locale_update_task(locale)
po_file = path.po_file.to_s
po_files << po_file

CLEAN << path.time_stamp_file.to_s if path.time_stamp_file.exist?
file po_file => [path.edit_po_file.to_s] do
GetText::Tools::MsgCat.run("--output", po_file,
"--sort-by-file",
Expand All @@ -158,6 +171,7 @@ def define_po_locale_update_task(locale)
"--remove-header-field=Language-Team",
"--remove-header-field=POT-Creation-Date",
path.edit_po_file.to_s)
touch(path.time_stamp_file.to_s)
end
end

Expand Down Expand Up @@ -284,6 +298,10 @@ def po_file
po_dir + "#{target_file_base}.po"
end

def time_stamp_file
po_dir + "#{target_file_base}.time_stamp"
end

def edit_po_file
po_dir + "#{target_file_base}.edit.po"
end
Expand Down

0 comments on commit 5bd93ac

Please sign in to comment.