Commit 2565220d authored by Jérémy Bobbio's avatar Jérémy Bobbio

Imported Upstream version 2.3.7

parent 9c08077d
--protected
--no-private
--output doc/reference/en
--title "gettext API Reference"
-
doc/text/*
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
gettext is copyrighted free software. See README.rdoc for
authors.
You can redistribute it and/or modify it under either the terms of the GPL
version 2 (see the file GPL), or the conditions below:
......
= gettext - Ruby-GetText-Package
= gettext - gettext for Ruby
Ruby-GetText-Package is a Localization(L10n) library and tool
Gettext gem is a pure Ruby Localization(L10n) library and tool
which is modeled after the GNU gettext package.
This library was called as "Ruby-GetText-Package". Since 2.3.0, this
library is called just "gettext". You can call this library as
"gettext gem" or "Ruby gettext" to distinguish from GNU gettext.
This library translates original messages to localized
messages using client-side locale information(environment
variable or CGI variable).
......@@ -25,7 +29,7 @@ Rails / ActiveRecord specific code now lives in locale_rails[http://github.com/m
returns translated messages of the current thread's locale.
* Tools to find message IDs
* Extract message IDs to po-files using rgettext from
* Extract message IDs to po-files using rxgettext from
* ruby scripts
* glade-2 XML file(.glade)
* ERB file(.rhtml, .erb)
......@@ -35,7 +39,7 @@ Rails / ActiveRecord specific code now lives in locale_rails[http://github.com/m
* rmsgfmt creates a mo-file from a po-file.
The mo-file is compatible to GNU gettext(msgfmt).
* Using rgettext/rmsgfmt as Rake tasks
* Using rxgettext/rmsgfmt as Rake tasks
* textdomain's scope is adapt to ruby class/module mechanism.
* A class/module can have plural textdomains.
......@@ -154,14 +158,10 @@ LGPL(Lesser General Public License: http://www.gnu.org/licenses/lgpl-3.0.txt).
* Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
* Copyright (C) 2001,2002 Masahiro Sakai <s01397ms at sfc.keio.ac.jp>
* rgettext
* rxgettext
* Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
* Copyright (C) 2001,2002 Yasushi Shoji <yashi at atmark-techno.com>
* setup.rb
* Copyright (C) 2000-2005 Minero Aoki <aamine at loveruby.net>
* This file is released under LGPL. See the top of the install.rb.
* Others
* Copyright (C) 2001-2009 Masao Mutoh <mutoh at highwhay.ne.jp>
......
# -*- ruby -*-
#
# Rakefile for Ruby-GetText-Package
# Rakefile for gettext
#
# This file maintains Ruby-GetText-Package.
# 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 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.
#
$:.unshift "./lib"
base_dir = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(base_dir, 'lib'))
require "tempfile"
require 'rake'
require 'rubygems'
require "yard/rake/yardoc_task"
require 'gettext/version'
require "rake"
require "rubygems"
require "yard"
require "gettext/version"
require "gettext/tools"
require "gettext/task"
require "bundler/gem_helper"
class Bundler::GemHelper
undef_method :version_tag
def version_tag
version
end
end
Bundler::GemHelper.install_tasks
PKG_VERSION = GetText::VERSION
helper = Bundler::GemHelper.new(base_dir)
helper.install
spec = helper.gemspec
task :default => :test
############################################################
# GetText tasks for developing
......@@ -38,13 +44,15 @@ poparser_rb_path = "lib/gettext/tools/poparser.rb"
desc "Create #{poparser_rb_path}"
task :poparser => poparser_rb_path
def fix_racc_output_indent(racc_output)
racc_output.gsub(/^ (end\s*\# module GetText)$/, '\1')
end
poparser_ry_path = "src/poparser.ry"
file poparser_rb_path => poparser_ry_path do
racc = File.join(Gem.bindir, "racc")
tempfile = Tempfile.new("gettext-poparser")
command_line = "#{racc} -g #{poparser_ry_path} -o #{tempfile.path}"
ruby(command_line)
$stderr.puts("ruby #{command_line}")
ruby(racc, "-g", poparser_ry_path, "-o", tempfile.path)
File.open(poparser_rb_path, "w") do |poparser_rb|
poparser_rb.puts(<<-EOH)
......@@ -60,164 +68,104 @@ file poparser_rb_path => poparser_ry_path do
EOH
poparser_rb.puts(tempfile.read)
poparser_rb.puts(fix_racc_output_indent(tempfile.read))
end
$stderr.puts "Create #{poparser_rb_path}."
end
desc "Create *.mo from *.po"
task :makemo do
require 'gettext/tools'
GetText.create_mofiles
$stderr.puts "Create samples mo files."
GetText.create_mofiles(
:po_root => "samples/po", :mo_root => "samples/locale")
$stderr.puts "Create samples/cgi mo files."
GetText.create_mofiles(
:po_root => "samples/cgi/po", :mo_root => "samples/cgi/locale")
$stderr.puts "Create test mo files."
GetText.create_mofiles(
:po_root => "test/po", :mo_root => "test/locale")
desc "Run all tests"
task :test => "test:prepare" do
options = ARGV - Rake.application.top_level_tasks
ruby "test/run-test.rb", *options
end
desc "Update pot/po files to match new version."
task :updatepo do
begin
require 'gettext'
require 'gettext/tools/poparser'
require 'gettext/tools'
rescue LoadError
puts "gettext/tools/poparser was not found."
end
#lib/gettext/*.rb -> rgettext.po
GetText.update_pofiles("rgettext",
Dir.glob("lib/**/*.rb") + ["src/poparser.ry"],
"ruby-gettext #{GetText::VERSION}")
namespace :test do
desc "Prepare test environment"
task :prepare => ["test:gettext", "samples:gettext"]
end
desc "Gather the newest po files. (for me)"
task :gatherpo => [:updatepo] do
mkdir_p "pofiles/original" unless FileTest.exist? "pofiles/original"
Dir.glob("**/*.pot").each do |f|
unless /^(pofiles|test)/ =~ f
copy f, "pofiles/original/"
end
GetText::Task.new(spec)
Dir.glob("samples/*.rb") do |target|
domain = File.basename(target, ".*")
GetText::Task.new(spec) do |task|
task.domain = domain
task.namespace_prefix = "samples:#{domain}"
task.po_base_directory = "samples/po"
task.mo_base_directory = "samples"
task.files = Dir.glob(target.gsub(/\..*\z/, ".*"))
end
Dir.glob("**/*.po").each do |f|
unless /^(pofiles|test)/ =~ f
lang = /po\/([^\/]*)\/(.*.po)/.match(f).to_a[1]
mkdir_p "pofiles/#{lang}" unless FileTest.exist? "pofiles/#{lang}"
copy f, "pofiles/#{lang}/"
Dir.glob("pofiles/original/*.pot").each do |f|
newpo = "pofiles/#{lang}/#{File.basename(f, ".pot")}.po"
copy f, newpo unless FileTest.exist? newpo
end
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::Task.new(spec) do |task|
task.domain = domain
task.namespace_prefix = "samples:cgi:#{domain}"
task.po_base_directory = "samples/cgi/po"
task.mo_base_directory = "samples/cgi"
task.files = files
end
task "samples:cgi:gettext" => "samples:cgi:#{domain}:gettext"
end
def mv_pofiles(src_dir, target_dir, lang)
target = File.join(target_dir, lang)
unless File.exist?(target)
mkdir_p target
sh "cvs add #{target}"
end
cvs_add_targets = ""
Dir.glob(File.join(target_dir, "ja/*.po")).sort.each do |f|
srcfile = File.join(src_dir, File.basename(f))
if File.exist?(srcfile)
unless File.exist?(File.join(target, File.basename(f)))
cvs_add_targets << File.join(target, File.basename(f)) + " "
end
mv srcfile, target, :verbose => true
else
puts "mv #{srcfile} #{target}/ -- skipped"
end
end
sh "cvs add #{cvs_add_targets}" if cvs_add_targets.size > 0
desc "Updates *.mo for CGI samples"
task "samples:cgi:gettext"
task "samples:gettext" => "samples:cgi:gettext"
["untranslated", "backslash", "non_ascii", "np_", "p_"].each do |domain|
GetText::Task.new(spec) do |task|
task.domain = domain
task.namespace_prefix = "test:#{domain}"
task.po_base_directory = "test/po"
task.mo_base_directory = "test"
task.files = ["test/fixtures/#{domain}.rb"]
task.locales = ["ja"]
end
task "test:gettext" => "test:#{domain}:gettext"
end
desc "Deploy localized pofiles to current source tree. (for me)"
task :deploypo do
srcdir = ENV["SRCDIR"] ||= File.join(ENV["HOME"], "pofiles")
lang = ENV["LOCALE"]
unless lang
puts "USAGE: rake deploypo [SRCDIR=#{ENV["HOME"]}/pofiles] LOCALE=ja"
exit
end
puts "SRCDIR = #{srcdir}, LOCALE = #{lang}"
mv_pofiles(srcdir, "po", lang)
mv_pofiles(srcdir, "samples/cgi/po", lang)
mv_pofiles(srcdir, "samples/po", lang)
["_", "s_", "ns_"].each do |domain|
GetText::Task.new(spec) do |task|
task.domain = domain
task.namespace_prefix = "test:#{domain}"
task.po_base_directory = "test/po"
task.mo_base_directory = "test"
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
task :package => [:makemo]
namespace :test do
namespace :pot do
pot_base_dir = "test/pot"
directory pot_base_dir
pot_paths = []
ruby_base_paths = [
"non_ascii", "npgettext", "nsgettext",
"pgettext", "backslash",
]
ruby_paths = Dir.glob("test/testlib/{#{ruby_base_paths.join(',')}}.rb")
ruby_paths.each do |ruby_path|
pot_base_path = File.basename(ruby_path).sub(/\.rb\z/, ".pot")
pot_path = "#{pot_base_dir}/#{pot_base_path}"
pot_paths << pot_path
file pot_path => [pot_base_dir, ruby_path] do
require "gettext/tools"
GetText.rgettext(ruby_path, pot_path)
end
po_only_domains = [
"plural", "plural_error", "rubyparser", "test1", "test2", "test3"
]
po_only_domains.each do |domain|
GetText::Task.new(spec) do |task|
task.domain = domain
task.namespace_prefix = "test:#{domain}"
task.po_base_directory = "test/po"
task.mo_base_directory = "test"
task.files = []
task.locales = Dir.glob("test/po/*/#{domain}.po").collect do |po|
File.basename(File.dirname(po))
end
desc "Update pot files for testing"
task :update => pot_paths
end
task "test:gettext" => "test:#{domain}:gettext"
end
desc "Update *.mo for test"
task "test:gettext"
namespace :mo do
mo_paths = []
language_paths = Dir.glob("test/po/*")
language_paths.each do |language_path|
language = File.basename(language_path)
po_paths = Dir.glob("#{language_path}/*.po")
po_paths.each do |po_path|
mo_base_path = File.basename(po_path).sub(/\.po\z/, ".mo")
mo_path = "test/locale/#{language}/LC_MESSAGES/#{mo_base_path}"
mo_paths << mo_path
file mo_path => [po_path, poparser_rb_path] do
require "gettext/tools"
GetText.rmsgfmt(po_path, mo_path)
end
end
end
desc "Update mo files for testing"
task :update => mo_paths
end
desc "Prepare test environment"
task :prepare => "test:mo:update"
end
task :package => [:gettext]
desc 'Run all tests'
task :test => "test:prepare" do
options = ARGV - Rake.application.top_level_tasks
ruby "test/run-test.rb", *options
end
task :build => [:gettext]
YARD::Rake::YardocTask.new do |t|
end
desc "Setup Ruby-GetText-Package. (for setup.rb)"
task :setup => [:makemo]
#! /usr/bin/ruby
=begin
rgettext - ruby version of xgettext
Copyright (C) 2005-2009 Masao Mutoh
You may redistribute it and/or modify it under the same
license terms as Ruby.
=end
begin
require 'gettext/rgettext'
rescue LoadError
begin
require 'rubygems'
require 'gettext/tools/rgettext'
rescue LoadError
raise 'Ruby-GetText-Package are not installed.'
end
end
GetText.rgettext
#! /usr/bin/ruby
=begin
rgettext - ruby version of xgettext
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
# Copyright (C) 2005-2009 Masao Mutoh
#
# License: Ruby's or LGPL
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2005-2009 Masao Mutoh
You may redistribute it and/or modify it under the same
license terms as Ruby.
=end
require "gettext/tools/msgfmt"
begin
require 'gettext/tools/rmsgfmt'
rescue LoadError
begin
require 'rubygems'
require 'gettext/tools/rmsgfmt'
rescue LoadError
raise 'Ruby-GetText-Package are not installed.'
end
end
GetText.rmsgfmt
GetText::Tools::MsgFmt.run(*ARGV)
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2012 Haruka Yoshihara <yoshihara@clear-code.com>
#
# License: Ruby's or LGPL
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require "gettext/tools/msginit"
begin
GetText::Tools::MsgInit.run(*ARGV)
rescue GetText::Tools::MsgInit::Error
puts($!.message)
exit(false)
end
#! /usr/bin/ruby
=begin
rmsgmerge - ruby version of msgmerge
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
# Copyright (C) 2005-2009 Masao Mutoh
#
# License: Ruby's or LGPL
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,