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 +2 -1
- data/Gemfile +22 -0
- data/README.rdoc +23 -24
- data/Rakefile +44 -82
- data/lib/locale.rb +25 -19
- data/lib/locale/driver.rb +24 -0
- data/lib/locale/driver/cgi.rb +61 -47
- data/lib/locale/driver/env.rb +35 -20
- data/lib/locale/driver/jruby.rb +24 -14
- data/lib/locale/driver/posix.rb +25 -16
- data/lib/locale/driver/win32.rb +33 -20
- data/lib/locale/info/language.rb +5 -1
- data/lib/locale/middleware.rb +38 -0
- data/lib/locale/version.rb +1 -1
- data/locale.gemspec +52 -0
- data/samples/rack/hello_rack.rb +4 -5
- data/samples/rack/locale_rack.rb +11 -0
- data/test/test_detect_cgi.rb +59 -58
- data/test/test_detect_general.rb +80 -5
- data/test/test_driver_jruby.rb +65 -43
- data/test/test_driver_win32.rb +65 -65
- data/test/test_info.rb +1 -0
- data/test/test_locale.rb +35 -0
- metadata +193 -69
- data/setup.rb +0 -1585
data/ChangeLog
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
= locale-2.0.5 (2009-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
|
data/README.rdoc
CHANGED
@@ -1,17 +1,22 @@
|
|
1
|
-
= Ruby
|
1
|
+
= locale - locale for Ruby
|
2
2
|
|
3
|
-
|
4
|
-
APIs for localization.
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
*
|
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
|
-
|
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
|
-
*
|
82
|
-
* by
|
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
|
-
|
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
|
-
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
|
data/lib/locale.rb
CHANGED
@@ -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
|
-
@@
|
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
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
case tag
|
38
|
+
when nil
|
39
|
+
when Locale::Tag::Simple
|
40
|
+
tag
|
41
|
+
when Locale::TagList
|
42
|
+
tag[0]
|
42
43
|
else
|
43
|
-
|
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
|
-
|
90
|
-
|
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
|
-
|
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
|
-
|
240
|
-
|
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
|
data/lib/locale/driver/cgi.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
74
|
+
def charset
|
75
|
+
req = Thread.current[:current_request]
|
76
|
+
return nil unless req
|
65
77
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
124
|
+
driver_module.set_request(query_langs, cookie_langs, accept_language, accept_charset)
|
111
125
|
self
|
112
126
|
end
|
113
127
|
|