Module: FastGettext::TranslationMultidomain
- Extended by:
- TranslationMultidomain
- Included in:
- TranslationMultidomain
- Defined in:
- lib/fast_gettext/translation.rb
Overview
this module should be included for multi-domain support
Class Method Summary collapse
-
.included(klas) ⇒ Object
make it usable in class definition, e.g.
Instance Method Summary collapse
-
#_in_domain(domain) ⇒ Object
helper block for changing domains.
-
#d_(domain, key, &block) ⇒ Object
gettext functions to translate in the context of given domain.
-
#D_(key) ⇒ Object
gettext functions to translate in the context of any domain (note: if mutiple domains contains key, random translation is returned).
- #dn_(domain, *keys, &block) ⇒ Object
- #Dn_(*keys) ⇒ Object
- #Dns_(*keys) ⇒ Object
- #dns_(domain, *keys, &block) ⇒ Object
- #ds_(domain, key, separator = nil, &block) ⇒ Object
- #Ds_(key, separator = nil) ⇒ Object
Class Method Details
.included(klas) ⇒ Object
make it usable in class definition, e.g. class Y
include FastGettext::TranslationMultidomain
@@x = d_('domain', 'y')
end
86 87 88 |
# File 'lib/fast_gettext/translation.rb', line 86 def self.included(klas) #:nodoc: klas.extend self end |
Instance Method Details
#_in_domain(domain) ⇒ Object
helper block for changing domains
91 92 93 94 95 96 97 |
# File 'lib/fast_gettext/translation.rb', line 91 def _in_domain domain old_domain = FastGettext.text_domain FastGettext.text_domain = domain yield if block_given? ensure FastGettext.text_domain = old_domain end |
#d_(domain, key, &block) ⇒ Object
gettext functions to translate in the context of given domain
100 101 102 103 104 |
# File 'lib/fast_gettext/translation.rb', line 100 def d_(domain, key, &block) _in_domain domain do FastGettext::Translation._(key, &block) end end |
#D_(key) ⇒ Object
gettext functions to translate in the context of any domain (note: if mutiple domains contains key, random translation is returned)
126 127 128 129 130 131 132 |
# File 'lib/fast_gettext/translation.rb', line 126 def D_(key) FastGettext.translation_repositories.each_key do |domain| result = FastGettext::TranslationMultidomain.d_(domain, key) {nil} return result unless result.nil? end key end |
#dn_(domain, *keys, &block) ⇒ Object
106 107 108 109 110 |
# File 'lib/fast_gettext/translation.rb', line 106 def dn_(domain, *keys, &block) _in_domain domain do FastGettext::Translation.n_(*keys, &block) end end |
#Dn_(*keys) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/fast_gettext/translation.rb', line 134 def Dn_(*keys) FastGettext.translation_repositories.each_key do |domain| result = FastGettext::TranslationMultidomain.dn_(domain, *keys) {nil} return result unless result.nil? end keys[-3].split(keys[-2]||NAMESPACE_SEPARATOR).last end |
#Dns_(*keys) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/fast_gettext/translation.rb', line 150 def Dns_(*keys) FastGettext.translation_repositories.each_key do |domain| result = FastGettext::TranslationMultidomain.dns_(domain, *keys) {nil} return result unless result.nil? end keys[-2].split(NAMESPACE_SEPARATOR).last end |
#dns_(domain, *keys, &block) ⇒ Object
118 119 120 121 122 |
# File 'lib/fast_gettext/translation.rb', line 118 def dns_(domain, *keys, &block) _in_domain domain do FastGettext::Translation.ns_(*keys, &block) end end |
#ds_(domain, key, separator = nil, &block) ⇒ Object
112 113 114 115 116 |
# File 'lib/fast_gettext/translation.rb', line 112 def ds_(domain, key, separator=nil, &block) _in_domain domain do FastGettext::Translation.s_(key, separator, &block) end end |
#Ds_(key, separator = nil) ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/fast_gettext/translation.rb', line 142 def Ds_(key, separator=nil) FastGettext.translation_repositories.each_key do |domain| result = FastGettext::TranslationMultidomain.ds_(domain, key, separator) {nil} return result unless result.nil? end key.split(separator||NAMESPACE_SEPARATOR).last end |