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
78 79 80 |
# File 'lib/fast_gettext/translation.rb', line 78 def self.included(klas) #:nodoc: klas.extend self end |
Instance Method Details
#_in_domain(domain) ⇒ Object
helper block for changing domains
83 84 85 86 87 88 89 |
# File 'lib/fast_gettext/translation.rb', line 83 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
92 93 94 95 96 |
# File 'lib/fast_gettext/translation.rb', line 92 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)
118 119 120 121 122 123 124 |
# File 'lib/fast_gettext/translation.rb', line 118 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
98 99 100 101 102 |
# File 'lib/fast_gettext/translation.rb', line 98 def dn_(domain, *keys, &block) _in_domain domain do FastGettext::Translation.n_(*keys, &block) end end |
#Dn_(*keys) ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/fast_gettext/translation.rb', line 126 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
142 143 144 145 146 147 148 |
# File 'lib/fast_gettext/translation.rb', line 142 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
110 111 112 113 114 |
# File 'lib/fast_gettext/translation.rb', line 110 def dns_(domain, *keys, &block) _in_domain domain do FastGettext::Translation.ns_(*keys, &block) end end |
#ds_(domain, key, separator = nil, &block) ⇒ Object
104 105 106 107 108 |
# File 'lib/fast_gettext/translation.rb', line 104 def ds_(domain, key, separator=nil, &block) _in_domain domain do FastGettext::Translation.s_(key, separator, &block) end end |
#Ds_(key, separator = nil) ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/fast_gettext/translation.rb', line 134 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 |