File: Rakefile

package info (click to toggle)
ruby-gettext 3.2.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,400 kB
  • sloc: ruby: 9,375; makefile: 8
file content (187 lines) | stat: -rw-r--r-- 5,411 bytes parent folder | download | duplicates (2)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# -*- ruby -*-
#
# Rakefile for gettext
#
# This file maintains gettext.
#
# Use setup.rb or gem for installation.
# You don't need to use this file directly.
#
# Copyright(c) 2005-2009 Masao Mutoh
# Copyright(c) 2012-2013 Kouhei Sutou <kou@clear-code.com>
# Copyright(c) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
# This program is licenced under the same licence as Ruby.

base_dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(base_dir, 'lib'))

require "tempfile"
require "rake"
require "rubygems"
require "yard"
require "gettext/version"
require "gettext/tools/task"

spec = Gem::Specification.load('gettext.gemspec')

task :default => :test

############################################################
# GetText tasks for developing
############################################################
po_parser_rb_path = "lib/gettext/po_parser.rb"
desc "Create #{po_parser_rb_path}"
task :po_parser => po_parser_rb_path

def fix_racc_output_indent(racc_output)
  racc_output.gsub(/^  (end\s*\# module GetText)$/, '\1')
end

po_parser_ry_path = "src/po_parser.ry"
file po_parser_rb_path => po_parser_ry_path do
  racc = "/usr/bin/racc"
  tempfile = Tempfile.new("gettext-po-parser")
  ruby(racc, "-g", po_parser_ry_path, "-o", tempfile.path)

  File.open(po_parser_rb_path, "w") do |po_parser_rb|
    po_parser_rb.puts(<<-EOH)
# -*- coding: utf-8 -*-
#
# po_parser.rb - Generate a .mo
#
# Copyright (C) 2003-2009 Masao Mutoh <mutomasa at gmail.com>
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
#
# You may redistribute it and/or modify it under the same
# license terms as Ruby or LGPL.

EOH

    po_parser_rb.puts(fix_racc_output_indent(tempfile.read))
  end
end

desc "Run all tests"
task :test => "test:prepare" do
  options = ARGV - Rake.application.top_level_tasks
  ruby "test/run-test.rb", *options
end

namespace :test do
  desc "Prepare test environment"
  task :prepare => [:po_parser, "test:gettext", "samples:gettext"]
end

xgettext_options = ["--add-comments=TRANSLATORS:"]
GetText::Tools::Task.define do |task|
  task.spec = spec
  task.xgettext_options.concat(xgettext_options)
end

Dir.glob("samples/*.rb") do |target|
  domain = File.basename(target, ".*")
  GetText::Tools::Task.define do |task|
    task.package_name = domain
    task.package_version = spec.version.to_s
    task.xgettext_options.concat(xgettext_options)
    task.domain = domain
    task.namespace_prefix = "samples:#{domain}"
    task.po_base_directory = "samples/po"
    task.mo_base_directory = "samples/locale"
    task.files = Dir.glob(target.gsub(/\..*\z/, ".*"))
  end
  task "samples:gettext" => "samples:#{domain}:gettext"
end
desc "Update *.mo for samples"
task "samples:gettext"

[
  ["main", Dir.glob("samples/cgi/{index.cgi,cookie.cgi}")],
  ["helloerb1", Dir.glob("samples/cgi/helloerb1.cgi")],
  ["helloerb2", Dir.glob("samples/cgi/helloerb2.cgi")],
  ["hellolib", Dir.glob("samples/cgi/hellolib.rb")],
].each do |domain, files|
  GetText::Tools::Task.define do |task|
    task.package_name = domain
    task.package_version = spec.version.to_s
    task.xgettext_options.concat(xgettext_options)
    task.domain = domain
    task.namespace_prefix = "samples:cgi:#{domain}"
    task.po_base_directory = "samples/cgi/po"
    task.mo_base_directory = "samples/cgi/locale"
    task.files = files
  end
  task "samples:cgi:gettext" => "samples:cgi:#{domain}:gettext"
end
desc "Updates *.mo for CGI samples"
task "samples:cgi:gettext"

task "samples:gettext" => "samples:cgi:gettext"

[
  "untranslated",
  "backslash",
  "non_ascii",
  "np_",
  "p_",
  "hello",
].each do |domain|
  GetText::Tools::Task.define do |task|
    task.package_name = domain
    task.package_version = spec.version.to_s
    task.xgettext_options.concat(xgettext_options)
    task.domain = domain
    task.namespace_prefix = "test:#{domain}"
    task.po_base_directory = "test/po"
    task.mo_base_directory = "test/locale"
    task.files = ["test/fixtures/#{domain}.rb"]
    task.locales = ["ja"]
  end
  task "test:gettext" => "test:#{domain}:gettext"
end

["_", "s_", "ns_"].each do |domain|
  GetText::Tools::Task.define do |task|
    task.package_name = domain
    task.package_version = spec.version.to_s
    task.xgettext_options.concat(xgettext_options)
    task.domain = domain
    task.namespace_prefix = "test:#{domain}"
    task.po_base_directory = "test/po"
    task.mo_base_directory = "test/locale"
    task.files = ["test/fixtures/#{domain}.rb"]
    task.files += Dir.glob("test/fixtures/#{domain}/*.rb")
    task.locales = ["ja"]
  end
  task "test:gettext" => "test:#{domain}:gettext"
end

po_only_domains = [
  "plural", "plural_error", "rubyparser", "test1", "test2", "test3"
]
po_only_domains.each do |domain|
  GetText::Tools::Task.define do |task|
    task.package_name = domain
    task.package_version = spec.version.to_s
    task.xgettext_options.concat(xgettext_options)
    task.domain = domain
    task.namespace_prefix = "test:#{domain}"
    task.po_base_directory = "test/po"
    task.mo_base_directory = "test/locale"
    task.enable_po = false
    task.locales = Dir.glob("test/po/*/#{domain}.po").collect do |po|
      File.basename(File.dirname(po))
    end
  end
  task "test:gettext" => "test:#{domain}:gettext"
end
desc "Update *.mo for test"
task "test:gettext"


task :package => [:gettext]

task :build => [:gettext]

YARD::Rake::YardocTask.new do |t|
end