Skip to content

Commit

Permalink
Fix wrong environment variable check
Browse files Browse the repository at this point in the history
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!!!
  • Loading branch information
kou committed Aug 22, 2012
1 parent 74ec738 commit 6ec43e9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/locale/driver/env.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Kouhei Sutou <[email protected]>
# Copyright (C) 2012 Hleb Valoshka
# Copyright (C) 2008 Masao Mutoh
#
# Original: Ruby-GetText-Package-1.92.0.
Expand Down Expand Up @@ -33,19 +34,19 @@ module Driver
module Env
module_function

# Gets the locale from environment variable. (LC_ALL > LC_MESSAGES > LANG)
# Gets the locale from environment variable. (LC_ALL > LC_CTYPES > LANG)
# Returns: the locale as Locale::Tag::Posix.
def locale
# At least one environment valiables should be set on *nix system.
[ENV["LC_ALL"], ENV["LC_MESSAGES"], ENV["LANG"]].each do |loc|
[ENV["LC_ALL"], ENV["LC_CTYPES"], ENV["LANG"]].each do |loc|
if loc != nil and loc.size > 0
return Locale::Tag::Posix.parse(loc)
end
end
nil
end

# Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG)
# Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG)
# * Returns: an Array of the locale as Locale::Tag::Posix or nil.
def locales
locales = ENV["LANGUAGE"]
Expand Down
2 changes: 1 addition & 1 deletion lib/locale/driver/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module Posix
$stderr.puts self.name + " is loaded." if $DEBUG

module_function
# Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_MESSAGES > LANG)
# Gets the locales from environment variables. (LANGUAGE > LC_ALL > LC_CTYPES > LANG)
# Only LANGUAGE accept plural languages such as "nl_BE;
# * Returns: an Array of the locale as Locale::Tag::Posix or nil.
def locales
Expand Down
11 changes: 6 additions & 5 deletions test/test_detect_general.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2012 Kouhei Sutou <[email protected]>
# Copyright (C) 2012 Hleb Valoshka
# Copyright (C) 2009-2010 Masao Mutoh
#
# License: Ruby's or LGPL
Expand All @@ -27,14 +28,14 @@ def setup
Locale.init
Locale.clear_all
ENV["LC_ALL"] = nil
ENV["LC_MESSAGES"] = nil
ENV["LC_CTYPES"] = nil
ENV["LANG"] = nil
ENV["LANGUAGE"] = nil
end

def test_lc_all
ENV["LC_ALL"] = "ja_JP.eucJP"
ENV["LC_MESSAGES"] = "zh_CN.UTF-8" #Ignored.
ENV["LC_CTYPES"] = "zh_CN.UTF-8" #Ignored.
ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
ENV["LANGUAGE"] = nil

Expand All @@ -50,7 +51,7 @@ def test_lc_all

def test_lc_messages
ENV["LC_ALL"] = nil
ENV["LC_MESSAGES"] = "ja_JP.eucJP"
ENV["LC_CTYPES"] = "ja_JP.eucJP"
ENV["LANG"] = "ko_KR.UTF-8" #Ignored.
ENV["LANGUAGE"] = nil

Expand All @@ -66,7 +67,7 @@ def test_lc_messages

def test_lang
ENV["LC_ALL"] = nil
ENV["LC_MESSAGES"] = nil
ENV["LC_CTYPES"] = nil
ENV["LANG"] = "ja_JP.eucJP"
ENV["LANGUAGE"] = nil

Expand All @@ -82,7 +83,7 @@ def test_lang

def test_lang_complex
ENV["LC_ALL"] = "zh_CN.UTF-8" # Ignored.
ENV["LC_MESSAGES"] = "ko_KR.UTF-8" #Ingored.
ENV["LC_CTYPES"] = "ko_KR.UTF-8" #Ingored.
ENV["LANG"] = "en_US.UTF-8" # Ignored.
ENV["LANGUAGE"] ="ja_JP.eucJP:zh_CN.UTF-8"

Expand Down
2 changes: 1 addition & 1 deletion test/test_driver_jruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestDiverJRuby < Test::Unit::TestCase

def setup
ENV["LC_ALL"] = nil
ENV["LC_MESSAGES"] = nil
ENV["LC_CTYPES"] = nil
ENV["LANG"] = nil
ENV["LANGUAGE"] = nil
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_driver_win32.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TestDiverWin32 < Test::Unit::TestCase

def setup
ENV["LC_ALL"] = nil
ENV["LC_MESSAGES"] = nil
ENV["LC_CTYPES"] = nil
ENV["LANG"] = nil
ENV["LANGUAGE"] = nil
Locale::Driver::Win32.set_thread_locale_id(nil)
Expand Down

0 comments on commit 6ec43e9

Please sign in to comment.