locale 2.0.5 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ChangeLog CHANGED
@@ -1,6 +1,7 @@
1
- = locale-2.0.5 (2009-11-11)
1
+ = locale-2.0.5 (2009-11-14)
2
2
  * Update license information(obiviously Ruby's and LGPL).
3
3
  [Pointed out by Masateru Yoshikawa]
4
+ * Fixed bugs [Bug #26995 by Thomas Nichols][Bug #26998 by Patrick Guiran]
4
5
 
5
6
  = locale-2.0.4 (2009-05-22)
6
7
  * Enhance Win32 support. [Reported by Dice]
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # License: Ruby's or LGPL
6
+ #
7
+ # This library is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ source :rubygems
21
+
22
+ gemspec
@@ -1,17 +1,22 @@
1
- = Ruby-Locale
1
+ = locale - locale for Ruby
2
2
 
3
- Ruby-Locale is the pure ruby library which provides basic and general purpose
4
- APIs for localization.
5
- It aims to support all environments which ruby works and all kind of programs
6
- (GUI, WWW, library, etc), and becomes the hub of other i18n/l10n libs/apps to
7
- handle major locale ID standards.
3
+ Locale gem is the pure ruby library which provides basic and general
4
+ purpose APIs for localization.
5
+
6
+ This library was called as "Ruby-Locale". Since 2.0.6, this library is
7
+ called just "locale". You can call this library as "locale gem" or
8
+ "Ruby Locale" to distinguish from other "locale"s.
9
+
10
+ This library aims to support all environments which Ruby works and all
11
+ kind of programs (GUI, WWW, library, etc), and becomes the hub of
12
+ other i18n/l10n libs/apps to handle major locale ID standards.
8
13
 
9
14
  * Manage Locale ID(Language Tag)
10
15
  * Each thread has a Locale ID.
11
16
  * POSIX, CLDR, IETF(RFC4646, 3066(BCP47)), Win32 and Java language tags
12
17
  and convert the tag string to each other.
13
18
  * Auto detect Locale ID.
14
- POSIX(Unix/Linux/*BSD), Win32, JRuby, CGI.
19
+ POSIX(Unix/Linux/*BSD), Win32, JRuby, CGI(CGI, Rack, others).
15
20
 
16
21
  * Resources
17
22
  * ISO 639-3 languages
@@ -20,24 +25,15 @@ handle major locale ID standards.
20
25
  * Support Ruby 1.8.7, Ruby 1.9.1, JRuby 1.1.4. Tested on Win32 and Linux.
21
26
 
22
27
  == Website
23
- * http://www.yotabanana.com/hiki/ruby-locale.html
24
- * http://locale.rubyforge.org/
28
+ * https://github.com/ruby-gettext/locale
25
29
 
26
30
  == Requirements
27
31
  * Ruby-1.8.7 or later <http://www.ruby-lang.org/ja/>
28
32
  * JRuby-1.1.4 or later <http://jruby.codehaus.org/>
29
33
 
30
34
  == Install
31
- * gem:
32
- ($ su)
33
- # gem install locale
34
35
 
35
- * tar-ball:
36
- Download tar-ball from http://rubyforge.org/projects/locale/
37
- De-Compress archive and enter its top directory.
38
- Then type:
39
- ($ su)
40
- # ruby setup.rb
36
+ % gem install locale
41
37
 
42
38
  == The simplest usage
43
39
 
@@ -63,10 +59,6 @@ LGPL(Lesser General Public License: http://www.gnu.org/licenses/lgpl-3.0.txt).
63
59
  * Copyright (C) 2006 Brian Pontarelli, Antonio Terceiro
64
60
  * Copyright (C) 2008,2009 Masao Mutoh <mutomasa at gmail.com>
65
61
 
66
- * setup.rb version 3.4.1
67
- * Copyright (C) 2000-2005 Minero Aoki <aamine at loveruby.net>
68
- * This file is released under LGPL. See the top of the setup.rb.
69
-
70
62
  * Others(Some files are separated from Ruby-GetText-Package-1.92.0)
71
63
  * Copyright (C) 2008,2009 Masao Mutoh <mutoh at highwhay.ne.jp>
72
64
 
@@ -78,8 +70,8 @@ LGPL(Lesser General Public License: http://www.gnu.org/licenses/lgpl-3.0.txt).
78
70
  * memoizable.rb
79
71
  * from ActiveSupport-2.2.0 <http://rubyforge.org/projects/activesupport/>
80
72
 
81
- * Ruby-GetText-Package-1.92.0
82
- * by Masao Mutoh <http://www.yotabanana.com/hiki/ruby-gettext.html>
73
+ * gettext gem
74
+ * by The ruby-gettext project <https://ruby-gettext.github.com/>
83
75
 
84
76
  === Documents
85
77
  * The Open Group Base Specifications Issue 6 IEEE Std 1003.1, 2004 Edition
@@ -108,4 +100,11 @@ LGPL(Lesser General Public License: http://www.gnu.org/licenses/lgpl-3.0.txt).
108
100
  * ISO 3166
109
101
 
110
102
  == Maintainer
103
+
104
+ === Active
105
+
106
+ Kouhei Sutou <kou@clear-code.com>
107
+
108
+ === Inactive
109
+
111
110
  Masao Mutoh <mutomasa at gmail.com>
data/Rakefile CHANGED
@@ -1,82 +1,44 @@
1
- $:.unshift "./lib"
2
-
3
- require 'rake'
4
- require 'rake/testtask'
5
- require 'rake/rdoctask'
6
- require 'rake/packagetask'
7
- require 'rake/gempackagetask'
8
-
9
- require 'locale/version'
10
-
11
- #desc "Default Task"
12
- #task :default => [ :test ]
13
-
14
- PKG_VERSION = Locale::VERSION
15
-
16
- # Run the unit tests
17
- task :test do
18
- Dir.glob("test/test_*.rb").each do |v|
19
- ruby "-Ilib #{v}"
20
- end
21
- end
22
-
23
- Rake::RDocTask.new { |rdoc|
24
- begin
25
- allison = `allison --path`.chop
26
- rescue Exception
27
- allison = ""
28
- end
29
- rdoc.rdoc_dir = 'doc'
30
- rdoc.title = "Ruby-Locale library"
31
- rdoc.options << "--line-numbers" << "--inline-source" <<
32
- "--accessor" << "cattr_accessor=object" << "--charset" << "utf-8"
33
- rdoc.rdoc_files.include('README.rdoc')
34
- rdoc.rdoc_files.include('ChangeLog')
35
- rdoc.rdoc_files.add('lib')
36
- rdoc.template = allison if allison.size > 0
37
- }
38
-
39
- desc "Create gem and tar.gz"
40
- spec = Gem::Specification.new do |s|
41
- s.name = 'locale'
42
- s.version = PKG_VERSION
43
- s.summary = 'Ruby-Locale is the pure ruby library which provides basic APIs for localization.'
44
- s.author = 'Masao Mutoh'
45
- s.email = 'mutomasa at gmail.com'
46
- s.homepage = 'http://locale.rubyforge.org/'
47
- s.rubyforge_project = "locale"
48
- s.files = FileList['**/*'].to_a.select{|v| v !~ /pkg|CVS/}
49
- s.require_path = 'lib'
50
- s.bindir = 'bin'
51
- s.has_rdoc = true
52
- s.description = <<-EOF
53
- Ruby-Locale is the pure ruby library which provides basic APIs for localization.
54
- EOF
55
- end
56
-
57
- unless RUBY_PLATFORM =~ /win32/
58
- Rake::PackageTask.new("ruby-locale", PKG_VERSION) do |o|
59
- o.package_files = FileList['**/*'].to_a.select{|v| v !~ /pkg|CVS/}
60
- o.need_tar_gz = true
61
- o.need_zip = false
62
- end
63
- end
64
-
65
- Rake::GemPackageTask.new(spec) do |p|
66
- p.gem_spec = spec
67
- p.need_tar_gz = false
68
- p.need_zip = false
69
- end
70
-
71
- desc "Publish the release files to RubyForge."
72
- task :release => [ :package ] do
73
- require 'rubyforge'
74
-
75
- rubyforge = RubyForge.new
76
- rubyforge.configure
77
- rubyforge.login
78
- rubyforge.add_release("locale", "locale",
79
- PKG_VERSION,
80
- "pkg/locale-#{PKG_VERSION}.gem",
81
- "pkg/ruby-locale-#{PKG_VERSION}.tar.gz")
82
- end
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # License: Ruby's or LGPL
6
+ #
7
+ # This library is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ require 'rake'
21
+ require 'rake/testtask'
22
+ require "bundler/gem_helper"
23
+
24
+ base_dir = File.expand_path(File.dirname(__FILE__))
25
+
26
+ desc "Run tests"
27
+ task :default => :test
28
+
29
+ class Bundler::GemHelper
30
+ undef_method :version_tag
31
+ def version_tag
32
+ version
33
+ end
34
+ end
35
+
36
+ helper = Bundler::GemHelper.new(base_dir)
37
+ helper.install
38
+ spec = helper.gemspec
39
+
40
+ desc "Run tests"
41
+ task :test do
42
+ options = ARGV - Rake.application.top_level_tasks
43
+ ruby("test/run-test.rb", *options)
44
+ end
@@ -1,6 +1,7 @@
1
1
  =begin
2
2
  locale.rb - Locale module
3
3
 
4
+ Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
5
  Copyright (C) 2002-2009 Masao Mutoh
5
6
 
6
7
  You may redistribute it and/or modify it under the same
@@ -14,6 +15,7 @@
14
15
  require 'locale/util/memoizable'
15
16
  require 'locale/tag'
16
17
  require 'locale/taglist'
18
+ require 'locale/driver'
17
19
  require 'locale/version'
18
20
 
19
21
  # Locale module manages the locale informations of the application.
@@ -21,26 +23,25 @@ require 'locale/version'
21
23
  # Almost of all i18n/l10n programs use this APIs only.
22
24
  module Locale
23
25
  @@default_tag = nil
24
- @@locale_driver_module = nil
25
-
26
- ROOT = File.dirname(__FILE__)
26
+ @@driver_name = nil
27
27
 
28
28
  include Locale::Util::Memoizable
29
29
 
30
30
  module_function
31
31
  def require_driver(name) #:nodoc:
32
- require File.join(ROOT, "locale/driver", name.to_s)
32
+ require "locale/driver/#{name}"
33
+ @@driver_name = name.to_sym
33
34
  end
34
35
 
35
36
  def create_language_tag(tag) #:nodoc:
36
- if tag
37
- if tag.kind_of? Locale::Tag::Simple
38
- tag
39
- else
40
- Locale::Tag.parse(tag)
41
- end
37
+ case tag
38
+ when nil
39
+ when Locale::Tag::Simple
40
+ tag
41
+ when Locale::TagList
42
+ tag[0]
42
43
  else
43
- nil
44
+ Locale::Tag.parse(tag)
44
45
  end
45
46
  end
46
47
 
@@ -86,10 +87,8 @@ module Locale
86
87
  #
87
88
  # * Returns: the driver module.
88
89
  def driver_module
89
- unless @@locale_driver_module
90
- Locale.init
91
- end
92
- @@locale_driver_module
90
+ Locale.init if @@driver_name.nil?
91
+ Driver::MODULES[@@driver_name]
93
92
  end
94
93
 
95
94
  DEFAULT_LANGUAGE_TAG = Locale::Tag::Simple.new("en") #:nodoc:
@@ -145,7 +144,12 @@ module Locale
145
144
  if tags[0]
146
145
  languages = Locale::TagList.new
147
146
  tags.each do |tag|
148
- languages << create_language_tag(tag)
147
+ case tag
148
+ when Locale::TagList
149
+ languages.concat(tag)
150
+ else
151
+ languages << create_language_tag(tag)
152
+ end
149
153
  end
150
154
  end
151
155
  Thread.current[:current_languages] = languages
@@ -236,9 +240,11 @@ module Locale
236
240
  end
237
241
 
238
242
  tags = []
239
- (0...candidate_tags[0].size).each {|i|
240
- tags += candidate_tags.collect{|v| v[i]}
241
- }
243
+ unless candidate_tags.empty?
244
+ (0...candidate_tags[0].size).each {|i|
245
+ tags += candidate_tags.collect{|v| v[i]}
246
+ }
247
+ end
242
248
  tags += default_tags
243
249
  tags.uniq!
244
250
 
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
+ #
5
+ # License: Ruby's or LGPL
6
+ #
7
+ # This library is free software: you can redistribute it and/or modify
8
+ # it under the terms of the GNU Lesser General Public License as published by
9
+ # the Free Software Foundation, either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # This library is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU Lesser General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Lesser General Public License
18
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+
20
+ module Locale
21
+ module Driver
22
+ MODULES = {}
23
+ end
24
+ end
@@ -1,15 +1,25 @@
1
- =begin
2
- locale/driver/cgi.rb
3
-
4
- Copyright (C) 2002-2008 Masao Mutoh
5
-
6
- You may redistribute it and/or modify it under the same
7
- license terms as Ruby.
8
-
9
- Original: Ruby-GetText-Package-1.92.0.
10
-
11
- $Id: cgi.rb 27 2008-12-03 15:06:50Z mutoh $
12
- =end
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2002-2008 Masao Mutoh
5
+ #
6
+ # Original: Ruby-GetText-Package-1.92.0.
7
+ # License: Ruby's or LGPL
8
+ #
9
+ # This library is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU Lesser General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # This library is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public License
20
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
21
+
22
+ require "locale/driver"
13
23
 
14
24
  module Locale
15
25
  # Locale::Driver module for CGI.
@@ -50,7 +60,9 @@ module Locale
50
60
  unless locales.size > 0
51
61
  # HTTP_ACCEPT_LANGUAGE
52
62
  if lang = req[:accept_language] and lang.size > 0
53
- locales += lang.gsub(/\s/, "").split(/,/).map{|v| v.split(";q=")}.map{|j| [j[0], j[1] ? j[1].to_f : 1.0]}.sort{|a,b| -(a[1] <=> b[1])}.map{|v| Locale::Tag.parse(v[0])}
63
+ # 10.0 is for ruby-1.8.6 which have the bug of str.to_f.
64
+ # Normally, this should be 1.0.
65
+ locales += lang.gsub(/\s/, "").split(/,/).map{|v| v.split(";q=")}.map{|j| [j[0], j[1] ? j[1].to_f : 10.0]}.sort{|a,b| -(a[1] <=> b[1])}.map{|v| Locale::Tag.parse(v[0])}
54
66
  end
55
67
  end
56
68
 
@@ -59,45 +71,47 @@ module Locale
59
71
 
60
72
  # Gets the charset from CGI parameters. (Based on RFC2616)
61
73
  # * Returns: the charset (HTTP_ACCEPT_CHARSET or nil).
62
- def charset
63
- req = Thread.current[:current_request]
64
- return nil unless req
74
+ def charset
75
+ req = Thread.current[:current_request]
76
+ return nil unless req
65
77
 
66
- charsets = req[:accept_charset]
67
- if charsets and charsets.size > 0
68
- num = charsets.index(',')
69
- charset = num ? charsets[0, num] : charsets
70
- charset = nil if charset == "*"
71
- else
72
- charset = nil
73
- end
74
- charset
75
- end
78
+ charsets = req[:accept_charset]
79
+ if charsets and charsets.size > 0
80
+ num = charsets.index(',')
81
+ charset = num ? charsets[0, num] : charsets
82
+ charset = nil if charset == "*"
83
+ else
84
+ charset = nil
85
+ end
86
+ charset
87
+ end
76
88
 
77
- # Set a request.
78
- #
79
- # * query_langs: An Array of QUERY_STRING value "lang".
80
- # * cookie_langs: An Array of cookie value "lang".
81
- # * accept_language: The value of HTTP_ACCEPT_LANGUAGE
82
- # * accept_charset: The value of HTTP_ACCEPT_CHARSET
83
- def set_request(query_langs, cookie_langs, accept_language, accept_charset)
84
- Thread.current[:current_request] = {
85
- :query_langs => query_langs,
86
- :cookie_langs => cookie_langs,
87
- :accept_language => accept_language,
88
- :accept_charset => accept_charset
89
- }
90
- self
91
- end
89
+ # Set a request.
90
+ #
91
+ # * query_langs: An Array of QUERY_STRING value "lang".
92
+ # * cookie_langs: An Array of cookie value "lang".
93
+ # * accept_language: The value of HTTP_ACCEPT_LANGUAGE
94
+ # * accept_charset: The value of HTTP_ACCEPT_CHARSET
95
+ def set_request(query_langs, cookie_langs, accept_language, accept_charset)
96
+ Locale.clear
97
+ Thread.current[:current_request] = {
98
+ :query_langs => query_langs,
99
+ :cookie_langs => cookie_langs,
100
+ :accept_language => accept_language,
101
+ :accept_charset => accept_charset
102
+ }
103
+ self
104
+ end
92
105
 
93
- # Clear the current request.
94
- def clear_current_request
95
- Thread.current[:current_request] = nil
96
- end
106
+ # Clear the current request.
107
+ def clear_current_request
108
+ Thread.current[:current_request] = nil
109
+ end
97
110
  end
111
+
112
+ MODULES[:cgi] = CGI
98
113
  end
99
114
 
100
- @@locale_driver_module = Driver::CGI
101
115
 
102
116
  module_function
103
117
  # Sets a request values for lang/charset.
@@ -107,7 +121,7 @@ module Locale
107
121
  # * accept_language: The value of HTTP_ACCEPT_LANGUAGE
108
122
  # * accept_charset: The value of HTTP_ACCEPT_CHARSET
109
123
  def set_request(query_langs, cookie_langs, accept_language, accept_charset)
110
- @@locale_driver_module.set_request(query_langs, cookie_langs, accept_language, accept_charset)
124
+ driver_module.set_request(query_langs, cookie_langs, accept_language, accept_charset)
111
125
  self
112
126
  end
113
127