locale 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,27 @@
1
1
  # News
2
2
 
3
+ ## <a id="2-0-9">2.0.9</a>: 2013-09-20
4
+
5
+ Locale handling fix release.
6
+
7
+ ### Improvements
8
+
9
+ * Added license metadata to gem package.
10
+ [GitHub#1] [Suggested by jordimassaguerpla]
11
+
12
+ ### Fixes
13
+
14
+ * Added missing .yardopts file.
15
+ * Fixed a bug that wrong environment value is used.
16
+ [Debian:#520181][Debian:#690572][GitHub#2]
17
+ [Reported by Stefano Zacchiroli][Reported by Hleb Valoshka]
18
+
19
+ ### Thanks
20
+
21
+ * jordimassaguerpla
22
+ * Stefano Zacchiroli
23
+ * Hleb Valoshka
24
+
3
25
  ## <a id="2-0-8">2.0.8</a>: 2012-08-29
4
26
 
5
27
  Package fix release.
@@ -24,29 +24,37 @@ require 'locale/tag'
24
24
  require 'locale/taglist'
25
25
  require "locale/driver"
26
26
 
27
- module Locale
27
+ module Locale
28
28
  module Driver
29
29
  # Locale::Driver::Env module.
30
30
  # Detect the user locales and the charset.
31
- # All drivers(except CGI) refer environment variables first and use it
31
+ # All drivers(except CGI) refer environment variables first and use it
32
32
  # as the locale if it's defined.
33
33
  # This is a low-level module. Application shouldn't use this directly.
34
34
  module Env
35
35
  module_function
36
36
 
37
- # Gets the locale from environment variable. (LC_ALL > LC_CTYPES > LANG)
37
+ # Gets the locale from environment variable.
38
+ # Priority order except charset is LC_ALL > LC_MESSAGES > LANG.
39
+ # Priority order for charset is LC_ALL > LC_CTYPE > LANG.
38
40
  # Returns: the locale as Locale::Tag::Posix.
39
41
  def locale
40
- # At least one environment valiables should be set on *nix system.
41
- [ENV["LC_ALL"], ENV["LC_CTYPES"], ENV["LANG"]].each do |loc|
42
- if loc != nil and loc.size > 0
43
- return Locale::Tag::Posix.parse(loc)
44
- end
45
- end
46
- nil
42
+ lc_all = Private.parse(ENV["LC_ALL"])
43
+ return lc_all if lc_all
44
+
45
+ lc_messages = Private.parse(ENV["LC_MESSAGES"])
46
+ lang = Private.parse(ENV["LANG"])
47
+
48
+ tag = lc_messages || lang
49
+ return nil if tag.nil?
50
+
51
+ lc_ctype = Private.parse(ENV["LC_CTYPE"])
52
+ tag.charset = lc_ctype.charset if lc_ctype
53
+
54
+ tag
47
55
  end
48
56
 
49
- # Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG)
57
+ # Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG)
50
58
  # * Returns: an Array of the locale as Locale::Tag::Posix or nil.
51
59
  def locales
52
60
  locales = ENV["LANGUAGE"]
@@ -61,16 +69,26 @@ module Locale
61
69
  nil
62
70
  end
63
71
 
64
- # Gets the charset from environment variable or return nil.
72
+ # Gets the charset from environment variables
73
+ # (LC_ALL > LC_CTYPE > LANG) or return nil.
65
74
  # * Returns: the system charset.
66
75
  def charset # :nodoc:
67
- if loc = locale
68
- loc.charset
69
- else
70
- nil
76
+ [ENV["LC_ALL"], ENV["LC_CTYPE"], ENV["LANG"]].each do |env|
77
+ tag = Private.parse(env)
78
+ next if tag.nil?
79
+ return tag.charset
80
+ end
81
+ nil
82
+ end
83
+
84
+ module Private
85
+ module_function
86
+ def parse(env_value)
87
+ return nil if env_value.nil?
88
+ return nil if env_value.empty?
89
+ Locale::Tag::Posix.parse(env_value)
71
90
  end
72
91
  end
73
-
74
92
  end
75
93
 
76
94
  MODULES[:env] = Env
@@ -30,7 +30,7 @@ module Locale
30
30
  $stderr.puts self.name + " is loaded." if $DEBUG
31
31
 
32
32
  module_function
33
- # Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG)
33
+ # Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG)
34
34
  # Only LANGUAGE accept plural languages such as "nl_BE;
35
35
  # * Returns: an Array of the locale as Locale::Tag::Posix or nil.
36
36
  def locales
@@ -46,11 +46,13 @@ module Locale
46
46
  end
47
47
  # Returns the top priority charset. (posix)
48
48
  def charset
49
- if self[0].respond_to? :charset
50
- self[0].charset
51
- else
52
- ::Locale.driver_module.charset
49
+ top_priority_charset = nil
50
+ first_tag = self[0]
51
+ if first_tag.respond_to?(:charset)
52
+ top_priority_charset = first_tag.charset
53
53
  end
54
+ top_priority_charset ||= ::Locale.driver_module.charset
55
+ top_priority_charset
54
56
  end
55
57
  memoize :charset
56
58
 
@@ -7,6 +7,6 @@
7
7
  license terms as Ruby.
8
8
  =end
9
9
  module Locale
10
- VERSION = "2.0.8"
10
+ VERSION = "2.0.9"
11
11
  end
12
12
 
@@ -1,6 +1,6 @@
1
1
  # -*- mode: ruby; coding: utf-8 -*-
2
2
  #
3
- # Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
3
+ # Copyright (C) 2012-2013 Kouhei Sutou <kou@clear-code.com>
4
4
  # Copyright (C) 2009 Masao Mutoh
5
5
  #
6
6
  # License: Ruby's or LGPL
@@ -32,6 +32,7 @@ Ruby-Locale is the pure ruby library which provides basic APIs for localization.
32
32
  s.authors = ["Kouhei Sutou", "Masao Mutoh"]
33
33
  s.email = ["kou@clear-code.com", "mutomasa at gmail.com"]
34
34
  s.homepage = "https://github.com/ruby-gettext/locale"
35
+ s.licenses = ["Ruby", "LGPLv3+"]
35
36
  s.require_paths = ["lib"]
36
37
  Dir.chdir(base_dir) do
37
38
  s.files = Dir.glob("{lib,samples}/**/*").find_all do |path|
@@ -28,14 +28,16 @@ class TestDetectGeneral < Test::Unit::TestCase
28
28
  Locale.init
29
29
  Locale.clear_all
30
30
  ENV["LC_ALL"] = nil
31
- ENV["LC_CTYPES"] = nil
31
+ ENV["LC_CTYPE"] = nil
32
+ ENV["LC_MESSAGES"] = nil
32
33
  ENV["LANG"] = nil
33
34
  ENV["LANGUAGE"] = nil
34
35
  end
35
36
 
36
37
  def test_lc_all
37
38
  ENV["LC_ALL"] = "ja_JP.eucJP"
38
- ENV["LC_CTYPES"] = "zh_CN.UTF-8" #Ignored.
39
+ ENV["LC_CTYPE"] = "fr_FR.ISO-8859-1" #Ignored.
40
+ ENV["LC_MESSAGES"] = "zh_CN.UTF-8" #Ignored.
39
41
  ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
40
42
  ENV["LANGUAGE"] = nil
41
43
 
@@ -51,8 +53,9 @@ class TestDetectGeneral < Test::Unit::TestCase
51
53
 
52
54
  def test_lc_messages
53
55
  ENV["LC_ALL"] = nil
54
- ENV["LC_CTYPES"] = "ja_JP.eucJP"
55
- ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
56
+ ENV["LC_CTYPE"] = nil
57
+ ENV["LC_MESSAGES"] = "ja_JP.eucJP"
58
+ ENV["LANG"] = "ko_KR.UTF-8" #Ignored except charset.
56
59
  ENV["LANGUAGE"] = nil
57
60
 
58
61
  lang = Locale.current[0]
@@ -62,12 +65,30 @@ class TestDetectGeneral < Test::Unit::TestCase
62
65
  assert_equal "eucJP", lang.charset
63
66
  assert_equal Locale::Tag::Posix.new("ja", "JP", "eucJP"), lang
64
67
 
65
- assert_equal "eucJP", Locale.charset
68
+ assert_equal "UTF-8", Locale.charset
69
+ end
70
+
71
+ def test_lc_messages_with_lc_ctype
72
+ ENV["LC_ALL"] = nil
73
+ ENV["LC_CTYPE"] = "fr_FR.ISO-8859-1"
74
+ ENV["LC_MESSAGES"] = "ja_JP.eucJP"
75
+ ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
76
+ ENV["LANGUAGE"] = nil
77
+
78
+ lang = Locale.current[0]
79
+ assert_equal Locale::Tag::Posix, lang.class
80
+ assert_equal "ja", lang.language
81
+ assert_equal "JP", lang.region
82
+ assert_equal "ISO-8859-1", lang.charset
83
+ assert_equal Locale::Tag::Posix.new("ja", "JP", "ISO-8859-1"), lang
84
+
85
+ assert_equal "ISO-8859-1", Locale.charset
66
86
  end
67
87
 
68
88
  def test_lang
69
89
  ENV["LC_ALL"] = nil
70
- ENV["LC_CTYPES"] = nil
90
+ ENV["LC_CTYPE"] = nil
91
+ ENV["LC_MESSAGES"] = nil
71
92
  ENV["LANG"] = "ja_JP.eucJP"
72
93
  ENV["LANGUAGE"] = nil
73
94
 
@@ -81,9 +102,27 @@ class TestDetectGeneral < Test::Unit::TestCase
81
102
  assert_equal "eucJP", Locale.charset
82
103
  end
83
104
 
105
+ def test_lang_with_ctype
106
+ ENV["LC_ALL"] = nil
107
+ ENV["LC_CTYPE"] = "fr_FR.ISO-8859-1"
108
+ ENV["LC_MESSAGES"] = nil
109
+ ENV["LANG"] = "ja_JP.eucJP"
110
+ ENV["LANGUAGE"] = nil
111
+
112
+ lang = Locale.current[0]
113
+ assert_equal Locale::Tag::Posix, lang.class
114
+ assert_equal "ja", lang.language
115
+ assert_equal "JP", lang.region
116
+ assert_equal "ISO-8859-1", lang.charset
117
+ assert_equal Locale::Tag::Posix.new("ja", "JP", "ISO-8859-1"), lang
118
+
119
+ assert_equal "ISO-8859-1", Locale.charset
120
+ end
121
+
84
122
  def test_lang_complex
85
123
  ENV["LC_ALL"] = "zh_CN.UTF-8" # Ignored.
86
- ENV["LC_CTYPES"] = "ko_KR.UTF-8" #Ingored.
124
+ ENV["LC_CTYPE"] = "fr_FR.ISO-8859-1" #Ingored.
125
+ ENV["LC_MESSAGES"] = "ko_KR.UTF-8" #Ingored.
87
126
  ENV["LANG"] = "en_US.UTF-8" # Ignored.
88
127
  ENV["LANGUAGE"] ="ja_JP.eucJP:zh_CN.UTF-8"
89
128
 
@@ -232,6 +271,40 @@ class TestDetectGeneral < Test::Unit::TestCase
232
271
 
233
272
  end
234
273
 
274
+ class TestCharset < self
275
+ def test_lc_all
276
+ ENV["LC_ALL"] = "ja_JP.eucJP"
277
+ ENV["LC_CTYPE"] = "ko_KR.eucKR" # Ignored.
278
+ ENV["LANG"] = "fr_FR.ISO-8859-1" # Ignored.
279
+
280
+ assert_equal("eucJP", Locale.charset)
281
+ end
282
+
283
+ def test_lc_ctype
284
+ ENV["LC_ALL"] = nil
285
+ ENV["LC_CTYPE"] = "ko_KR.eucKR"
286
+ ENV["LANG"] = "fr_FR.ISO-8859-1" # Ignored.
287
+
288
+ assert_equal("eucKR", Locale.charset)
289
+ end
290
+
291
+ def test_lc_messages
292
+ ENV["LC_ALL"] = nil
293
+ ENV["LC_MESSAGES"] = "ko_KR.eucKR" # Ignored.
294
+ ENV["LANG"] = "fr_FR.ISO-8859-1"
295
+
296
+ assert_equal("ISO-8859-1", Locale.charset)
297
+ end
298
+
299
+ def test_lang
300
+ ENV["LC_ALL"] = nil
301
+ ENV["LC_CTYPE"] = nil
302
+ ENV["LANG"] = "fr_FR.ISO-8859-1"
303
+
304
+ assert_equal("ISO-8859-1", Locale.charset)
305
+ end
306
+ end
307
+
235
308
  private
236
309
  def jruby?
237
310
  RUBY_PLATFORM == "java"
@@ -26,7 +26,7 @@ begin
26
26
 
27
27
  def setup
28
28
  ENV["LC_ALL"] = nil
29
- ENV["LC_CTYPES"] = nil
29
+ ENV["LC_CTYPE"] = nil
30
30
  ENV["LANG"] = nil
31
31
  ENV["LANGUAGE"] = nil
32
32
  end
@@ -6,7 +6,7 @@ begin
6
6
 
7
7
  def setup
8
8
  ENV["LC_ALL"] = nil
9
- ENV["LC_CTYPES"] = nil
9
+ ENV["LC_CTYPE"] = nil
10
10
  ENV["LANG"] = nil
11
11
  ENV["LANGUAGE"] = nil
12
12
  Locale::Driver::Win32.set_thread_locale_id(nil)
@@ -31,4 +31,31 @@ class TestTagList < Test::Unit::TestCase
31
31
  assert_equal ["y-aaa"], list.extensions
32
32
  assert_equal "x-bbb", list.privateuse
33
33
  end
34
+
35
+ class TestCharset < self
36
+ def setup
37
+ ENV["LC_ALL"] = nil
38
+ ENV["LC_CTYPE"] = nil
39
+ ENV["LANG"] = nil
40
+ ENV["LANGUAGE"] = nil
41
+ end
42
+
43
+ def test_empty
44
+ list = Locale::TagList.new
45
+ ENV["LC_ALL"] = "en_US.UTF-8"
46
+ assert_equal("UTF-8", list.charset)
47
+ end
48
+
49
+ def test_have_charset_tag
50
+ list = Locale::TagList.new([Locale::Tag.parse("en_US.ISO-8859-1")])
51
+ ENV["LC_ALL"] = "en_US.UTF-8"
52
+ assert_equal("ISO-8859-1", list.charset)
53
+ end
54
+
55
+ def test_no_charset_tag
56
+ list = Locale::TagList.new([Locale::Tag.parse("en_US")])
57
+ ENV["LC_ALL"] = "en_US.UTF-8"
58
+ assert_equal("UTF-8", list.charset)
59
+ end
60
+ end
34
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locale
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-08-29 00:00:00.000000000 Z
13
+ date: 2013-09-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -135,41 +135,41 @@ executables: []
135
135
  extensions: []
136
136
  extra_rdoc_files: []
137
137
  files:
138
- - lib/locale/tag/simple.rb
138
+ - lib/locale/version.rb
139
+ - lib/locale/tag.rb
140
+ - lib/locale/tag/cldr.rb
139
141
  - lib/locale/tag/posix.rb
140
142
  - lib/locale/tag/common.rb
141
- - lib/locale/tag/cldr.rb
142
- - lib/locale/tag/rfc.rb
143
+ - lib/locale/tag/simple.rb
143
144
  - lib/locale/tag/irregular.rb
144
- - lib/locale/info.rb
145
- - lib/locale/data/languages.tab.gz
146
- - lib/locale/data/regions.tab.gz
147
- - lib/locale/middleware.rb
148
- - lib/locale/version.rb
149
- - lib/locale/info/region.rb
145
+ - lib/locale/tag/rfc.rb
150
146
  - lib/locale/info/language.rb
151
- - lib/locale/driver/env.rb
152
- - lib/locale/driver/posix.rb
153
- - lib/locale/driver/jruby.rb
147
+ - lib/locale/info/region.rb
148
+ - lib/locale/driver.rb
154
149
  - lib/locale/driver/cgi.rb
155
- - lib/locale/driver/win32_table.rb
150
+ - lib/locale/driver/posix.rb
151
+ - lib/locale/driver/env.rb
156
152
  - lib/locale/driver/win32.rb
157
- - lib/locale/taglist.rb
158
- - lib/locale/driver.rb
159
- - lib/locale/tag.rb
153
+ - lib/locale/driver/win32_table.rb
154
+ - lib/locale/driver/jruby.rb
155
+ - lib/locale/info.rb
156
+ - lib/locale/middleware.rb
157
+ - lib/locale/data/languages.tab.gz
158
+ - lib/locale/data/regions.tab.gz
160
159
  - lib/locale/util/memoizable.rb
160
+ - lib/locale/taglist.rb
161
161
  - lib/locale.rb
162
- - samples/rack/hello_rack.rb
163
- - samples/rack/README
164
- - samples/rack/locale_rack.rb
165
- - samples/rack/hello_rack.ru
166
162
  - samples/cgi/README
167
- - samples/cgi/cookie.cgi
168
- - samples/cgi/locale.css
169
163
  - samples/cgi/index.cgi
164
+ - samples/cgi/locale.css
170
165
  - samples/cgi/http.rb
171
- - samples/sample_info.rb
166
+ - samples/cgi/cookie.cgi
167
+ - samples/rack/README
168
+ - samples/rack/locale_rack.rb
169
+ - samples/rack/hello_rack.rb
170
+ - samples/rack/hello_rack.ru
172
171
  - samples/sample_1.rb
172
+ - samples/sample_info.rb
173
173
  - COPYING
174
174
  - ChangeLog
175
175
  - README.rdoc
@@ -178,18 +178,20 @@ files:
178
178
  - locale.gemspec
179
179
  - .yardopts
180
180
  - doc/text/news.md
181
- - test/test_driver_jruby.rb
182
- - test/test_taglist.rb
183
- - test/test_detect_general.rb
184
- - test/test_driver_win32.rb
185
- - test/test_thread.rb
186
- - test/test_memoizable.rb
181
+ - test/test_tag.rb
187
182
  - test/test_detect_cgi.rb
183
+ - test/test_taglist.rb
188
184
  - test/test_locale.rb
185
+ - test/test_thread.rb
189
186
  - test/test_info.rb
190
- - test/test_tag.rb
187
+ - test/test_memoizable.rb
188
+ - test/test_driver_jruby.rb
189
+ - test/test_driver_win32.rb
190
+ - test/test_detect_general.rb
191
191
  homepage: https://github.com/ruby-gettext/locale
192
- licenses: []
192
+ licenses:
193
+ - Ruby
194
+ - LGPLv3+
193
195
  post_install_message:
194
196
  rdoc_options: []
195
197
  require_paths:
@@ -213,14 +215,14 @@ signing_key:
213
215
  specification_version: 3
214
216
  summary: Ruby-Locale is the pure ruby library which provides basic APIs for localization.
215
217
  test_files:
216
- - test/test_driver_jruby.rb
217
- - test/test_taglist.rb
218
- - test/test_detect_general.rb
219
- - test/test_driver_win32.rb
220
- - test/test_thread.rb
221
- - test/test_memoizable.rb
218
+ - test/test_tag.rb
222
219
  - test/test_detect_cgi.rb
220
+ - test/test_taglist.rb
223
221
  - test/test_locale.rb
222
+ - test/test_thread.rb
224
223
  - test/test_info.rb
225
- - test/test_tag.rb
224
+ - test/test_memoizable.rb
225
+ - test/test_driver_jruby.rb
226
+ - test/test_driver_win32.rb
227
+ - test/test_detect_general.rb
226
228
  has_rdoc: