Module: Locale

Defined in:
lib/locale.rb,
lib/locale/cgi.rb,
lib/locale/base.rb,
lib/locale/jruby.rb,
lib/locale/posix.rb,
lib/locale/win32.rb,
lib/locale/object.rb,
lib/locale/win32_table.rb

Overview

locale_table_win32.rb - Locale table for win32

Copyright (C) 2002-2008 Masao Mutoh <[email protected]>

You may redistribute it and/or modify it under the same
license terms as Ruby.

$Id: win32_table.rb,v 1.4 2008/03/21 06:28:10 mutoh Exp $

Defined Under Namespace

Modules: SystemBase, SystemCGI, SystemJRuby, SystemPosix, SystemWin32, SystemWin32Table Classes: Object

Constant Summary collapse

@@default =
nil
@@current =
nil
@@locale_system_module =
SystemWin32

Class Method Summary collapse

Class Method Details

.cgiObject

Gets the CGI object. If it is nil, returns new CGI object.

  • Returns: the CGI object



100
101
102
# File 'lib/locale/cgi.rb', line 100

def cgi
  @@locale_system_module.cgi
end

.cgi=(cgi_) ⇒ Object

Sets a CGI object.

  • cgi_: CGI object

  • Returns: cgi_



93
94
95
96
# File 'lib/locale/cgi.rb', line 93

def cgi=(cgi_)
  set_cgi(cgi_)
  cgi_
end

.charsetObject

Gets the charset of the current locale.

  • Returns: the charset of the current locale (String)



161
162
163
# File 'lib/locale.rb', line 161

def charset
  codeset
end

.clearObject

Clear default/current locale.

  • Returns: self



172
173
174
175
176
# File 'lib/locale.rb', line 172

def clear
  set(nil)
  set_current(nil)
  self
end

.codesetObject

Same as charset. Gets the charset of the current locale.

  • Returns: the charset of the current locale (String)



155
156
157
# File 'lib/locale.rb', line 155

def codeset
  current.charset
end

.currentObject

Gets the current locale (Locale::Object).

If the current locale is not set, this returns default locale.

  • Returns: the current locale (Locale::Object).



72
73
74
75
# File 'lib/locale.rb', line 72

def current
  @@current = default unless @@current
  @@current
end

.current=(lang) ⇒ Object

Sets a current locale. This is a single argument version of Locale.set_current.



111
112
113
114
# File 'lib/locale.rb', line 111

def current=(lang)
  set_current(lang)
  @@current
end

.current_charsetObject

Same as codeset. Returns the charset of the current locale.

  • Returns: the charset of the current locale (String)



166
167
168
# File 'lib/locale.rb', line 166

def current_charset
  codeset
end

.defaultObject

Gets the default locale.

If the default locale not set, this returns system locale.

  • Returns: the default locale (Locale::Object).



64
65
66
# File 'lib/locale.rb', line 64

def default
  @@default ? @@default : system
end

.default=(locale) ⇒ Object

Same as Locale.set_default.

  • locale: the default locale (Locale::Object).

  • Returns: locale.



49
50
51
52
# File 'lib/locale.rb', line 49

def default=(locale)
  set_default(locale)
  @@default
end

.getObject

call-seq:

current
get
  • Returns: the current locale (Locale::Object).

Notice: lctype is deprecated. Use this with no parameter instead.



148
149
150
151
# File 'lib/locale.rb', line 148

def get
  @@current = default unless @@current
  @@current
end

.set(lang, country = nil, charset = nil) ⇒ Object

call-seq:

set(lang)
set(lang, country = nil, charset = nil)
  • lang: language as String, or Locale::Object

  • country: country as String or nil

  • charset: charset as String or nil

  • Returns: a Locale::Object.

Sets a default locale. This function is an alias of Locale.set_default with calling set_current(nil).

Notice: Locale.set(lctype, locale) is deprecated.



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/locale.rb', line 129

def set(lang, country = nil, charset = nil)
  set_current(nil)
  if lang.kind_of? String
    set_default(Locale::Object.new(lang, country, charset))
  elsif lang.kind_of? Locale::Object
    set_default(lang)
  else
    set_default(nil)
  end
  @@default
end

.set_cgi(cgi_) ⇒ Object

Sets a CGI object.

  • cgi_: CGI object

  • Returns: self



85
86
87
88
# File 'lib/locale/cgi.rb', line 85

def set_cgi(cgi_)
  @@locale_system_module.set_cgi(cgi_)
  self
end

.set_current(lang, country = nil, charset = nil) ⇒ Object

Sets a locale as the current locale.

This returns the current Locale::Object.

  • lang: Locale::Object or locale name(String), or language name.

  • country: the country code(String)

  • charset: the charset(override the charset even if the locale name has charset).

  • Returns: self

    Locale.set_current("ja_JP.eucJP")
    Locale.set_current("ja", "JP")
    Locale.set_current("ja", "JP", "eucJP")
    Locale.set_current("ja", nil, "eucJP")
    Locale.set_current(Locale::Object.new("ja", "JP", "eucJP"))
    


90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/locale.rb', line 90

def set_current(lang, country = nil, charset = nil)
  if lang == nil
    @@current = nil
  else
    if lang.kind_of? Locale::Object
	@@current = lang
    else
	@@current = Locale::Object.new(lang, country, charset)
    end
    @@current.charset ||= @@locale_system_module.charset
  end
  self
end

.set_default(locale) ⇒ Object

Sets the default locale (Locale::Object or String(such as ja_JP.eucJP)).

  • locale: the default locale

  • Returns: self.



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/locale.rb', line 32

def set_default(locale)
  if locale
    if locale.kind_of? Locale::Object
      @@default = locale
    else
      @@default = Locale::Object.new(locale)
    end
    @@default.charset ||= @@locale_system_module.charset
  else
    @@default = nil
  end
  self
end

.systemObject

Gets the system locale.

  • Returns: the system locale (Locale::Object).



56
57
58
# File 'lib/locale.rb', line 56

def system
  @@locale_system_module.system
end

.system_moduleObject

Gets the current system module. This is used for debugging.

  • Returns: the system module.



180
181
182
# File 'lib/locale.rb', line 180

def system_module
  @@locale_system_module
end