Skip to content

Commit 6ec43e9

Browse files
committed
Fix wrong environment variable check
LC_CTYPES should be checked instead of LC_MESSAGES. Fix the third report of mutoh#5. Debian bug #520181: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=520181 Patch by Hleb Valoshka. Thanks!!! Rreported by Adeodato Simó. Thanks!!!
1 parent 74ec738 commit 6ec43e9

5 files changed

Lines changed: 13 additions & 11 deletions

File tree

lib/locale/driver/env.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4+
# Copyright (C) 2012 Hleb Valoshka
45
# Copyright (C) 2008 Masao Mutoh
56
#
67
# Original: Ruby-GetText-Package-1.92.0.
@@ -33,19 +34,19 @@ module Driver
3334
module Env
3435
module_function
3536

36-
# Gets the locale from environment variable. (LC_ALL > LC_MESSAGES > LANG)
37+
# Gets the locale from environment variable. (LC_ALL > LC_CTYPES > LANG)
3738
# Returns: the locale as Locale::Tag::Posix.
3839
def locale
3940
# At least one environment valiables should be set on *nix system.
40-
[ENV["LC_ALL"], ENV["LC_MESSAGES"], ENV["LANG"]].each do |loc|
41+
[ENV["LC_ALL"], ENV["LC_CTYPES"], ENV["LANG"]].each do |loc|
4142
if loc != nil and loc.size > 0
4243
return Locale::Tag::Posix.parse(loc)
4344
end
4445
end
4546
nil
4647
end
4748

48-
# Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG)
49+
# Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG)
4950
# * Returns: an Array of the locale as Locale::Tag::Posix or nil.
5051
def locales
5152
locales = ENV["LANGUAGE"]

lib/locale/driver/posix.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module Posix
3030
$stderr.puts self.name + " is loaded." if $DEBUG
3131

3232
module_function
33-
# Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG)
33+
# Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG)
3434
# Only LANGUAGE accept plural languages such as "nl_BE;
3535
# * Returns: an Array of the locale as Locale::Tag::Posix or nil.
3636
def locales

test/test_detect_general.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22
#
33
# Copyright (C) 2012 Kouhei Sutou <kou@clear-code.com>
4+
# Copyright (C) 2012 Hleb Valoshka
45
# Copyright (C) 2009-2010 Masao Mutoh
56
#
67
# License: Ruby's or LGPL
@@ -27,14 +28,14 @@ def setup
2728
Locale.init
2829
Locale.clear_all
2930
ENV["LC_ALL"] = nil
30-
ENV["LC_MESSAGES"] = nil
31+
ENV["LC_CTYPES"] = nil
3132
ENV["LANG"] = nil
3233
ENV["LANGUAGE"] = nil
3334
end
3435

3536
def test_lc_all
3637
ENV["LC_ALL"] = "ja_JP.eucJP"
37-
ENV["LC_MESSAGES"] = "zh_CN.UTF-8" #Ignored.
38+
ENV["LC_CTYPES"] = "zh_CN.UTF-8" #Ignored.
3839
ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
3940
ENV["LANGUAGE"] = nil
4041

@@ -50,7 +51,7 @@ def test_lc_all
5051

5152
def test_lc_messages
5253
ENV["LC_ALL"] = nil
53-
ENV["LC_MESSAGES"] = "ja_JP.eucJP"
54+
ENV["LC_CTYPES"] = "ja_JP.eucJP"
5455
ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
5556
ENV["LANGUAGE"] = nil
5657

@@ -66,7 +67,7 @@ def test_lc_messages
6667

6768
def test_lang
6869
ENV["LC_ALL"] = nil
69-
ENV["LC_MESSAGES"] = nil
70+
ENV["LC_CTYPES"] = nil
7071
ENV["LANG"] = "ja_JP.eucJP"
7172
ENV["LANGUAGE"] = nil
7273

@@ -82,7 +83,7 @@ def test_lang
8283

8384
def test_lang_complex
8485
ENV["LC_ALL"] = "zh_CN.UTF-8" # Ignored.
85-
ENV["LC_MESSAGES"] = "ko_KR.UTF-8" #Ingored.
86+
ENV["LC_CTYPES"] = "ko_KR.UTF-8" #Ingored.
8687
ENV["LANG"] = "en_US.UTF-8" # Ignored.
8788
ENV["LANGUAGE"] ="ja_JP.eucJP:zh_CN.UTF-8"
8889

test/test_driver_jruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestDiverJRuby < Test::Unit::TestCase
2626

2727
def setup
2828
ENV["LC_ALL"] = nil
29-
ENV["LC_MESSAGES"] = nil
29+
ENV["LC_CTYPES"] = nil
3030
ENV["LANG"] = nil
3131
ENV["LANGUAGE"] = nil
3232
end

test/test_driver_win32.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class TestDiverWin32 < Test::Unit::TestCase
66

77
def setup
88
ENV["LC_ALL"] = nil
9-
ENV["LC_MESSAGES"] = nil
9+
ENV["LC_CTYPES"] = nil
1010
ENV["LANG"] = nil
1111
ENV["LANGUAGE"] = nil
1212
Locale::Driver::Win32.set_thread_locale_id(nil)

0 commit comments

Comments
 (0)