Class: GetText::TextDomainManager
- Inherits:
-
Object
- Object
- GetText::TextDomainManager
- Includes:
- Enumerable
- Defined in:
- lib/gettext/textdomainmanager.rb
Overview
Manage TextDomain (Internal use only) A class/module is able to have plural textdomains.
Constant Summary collapse
- @@output_charset =
ENV["OUTPUT_CHARSET"]
- @@textdomain_all =
{}
Instance Attribute Summary collapse
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#textdomains ⇒ Object
readonly
Returns the value of attribute textdomains.
Class Method Summary collapse
- .each_all ⇒ Object
-
.output_charset ⇒ Object
Gets the current output_charset.
-
.output_charset=(charset) ⇒ Object
Sets the current output_charset.
- .textdomain(domainname) ⇒ Object
Instance Method Summary collapse
-
#add_textdomain(domainname, options = {}) ⇒ Object
Add a textdomain * options: If they aren’t set or invalid, default values are used.
-
#each ⇒ Object
Iterate textdomains.
-
#initialize(target, locale) ⇒ TextDomainManager
constructor
Initialize a TextDomainManager * target: a target class/module to bind this TextDomainManager.
-
#set_locale(locale, force = false) ⇒ Object
Sets locale such as “de”, “fr”, “it”, “ko”, “ja_JP.eucJP”, “zh_CN.EUC” …
Constructor Details
#initialize(target, locale) ⇒ TextDomainManager
Initialize a TextDomainManager
-
target: a target class/module to bind this TextDomainManager.
-
locale: a Locale::Object.
52 53 54 55 56 |
# File 'lib/gettext/textdomainmanager.rb', line 52 def initialize(target, locale) @target = target @locale = locale @textdomains = {} end |
Instance Attribute Details
#target ⇒ Object (readonly)
Returns the value of attribute target.
21 22 23 |
# File 'lib/gettext/textdomainmanager.rb', line 21 def target @target end |
#textdomains ⇒ Object (readonly)
Returns the value of attribute textdomains.
21 22 23 |
# File 'lib/gettext/textdomainmanager.rb', line 21 def textdomains @textdomains end |
Class Method Details
.each_all ⇒ Object
39 40 41 42 43 |
# File 'lib/gettext/textdomainmanager.rb', line 39 def self.each_all @@textdomain_all.each do |k, textdomain| yield textdomain end end |
.output_charset ⇒ Object
Gets the current output_charset.
-
Returns: output_charset.
35 36 37 |
# File 'lib/gettext/textdomainmanager.rb', line 35 def self.output_charset @@output_charset end |
.output_charset=(charset) ⇒ Object
Sets the current output_charset.
-
charset: output_charset.
-
Returns: output_charset.
29 30 31 |
# File 'lib/gettext/textdomainmanager.rb', line 29 def self.output_charset=(charset) @@output_charset = charset end |
.textdomain(domainname) ⇒ Object
45 46 47 |
# File 'lib/gettext/textdomainmanager.rb', line 45 def self.textdomain(domainname) @@textdomain_all[domainname] end |
Instance Method Details
#add_textdomain(domainname, options = {}) ⇒ Object
Add a textdomain
-
options: If they aren’t set or invalid, default values are used.
-
:path - the path to the mo-files. If not set, it will search default paths such as /usr/share/locale, /usr/local/share/locale)
-
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/gettext/textdomainmanager.rb', line 62 def add_textdomain(domainname, = {}) path = [:path] if $DEBUG $stderr.print "Bind the domain '#{domainname}' to '#{@target}'. " $stderr.print "Current locale is #{@locale.inspect}\n" end textdomain = @@textdomain_all[domainname] if textdomain textdomain.set_locale(@locale) else textdomain = TextDomain.new(domainname, path, @locale) @@textdomain_all[domainname] = textdomain end @textdomains[domainname] = textdomain textdomain end |
#each ⇒ Object
Iterate textdomains.
80 81 82 83 84 85 |
# File 'lib/gettext/textdomainmanager.rb', line 80 def each @textdomains.each do |k, textdomain| yield textdomain end self end |
#set_locale(locale, force = false) ⇒ Object
Sets locale such as “de”, “fr”, “it”, “ko”, “ja_JP.eucJP”, “zh_CN.EUC” …
Notice that you shouldn’t use this for your own Libraries.
-
locale: a locale string or Locale::Object.
-
force: Change locale forcely.
-
Returns: self
93 94 95 96 97 98 99 100 101 |
# File 'lib/gettext/textdomainmanager.rb', line 93 def set_locale(locale, force = false) if locale != @locale or force each do |textdomain| textdomain.set_locale(locale, force) end @locale = locale end self end |