Method: I18n::Backend::Inflector#shorten_inflection_alias
- Defined in:
- lib/i18n-inflector/backend.rb
permalink #shorten_inflection_alias(token, kind, locale) ⇒ Symbol (protected) #shorten_inflection_alias(token, kind, locale, subtree) ⇒ Symbol (protected)
Note:
It does take care of aliasing loops (max traverses is set to 64).
Resolves an alias for a token if the given token
is an alias.
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/i18n-inflector/backend.rb', line 192 def shorten_inflection_alias(token, kind, locale, subtree=nil, count=0) count += 1 return nil if count > 64 inflections_tree = subtree || inflection_subtree(locale) return nil if (inflections_tree.nil? || inflections_tree.empty?) kind_subtree = inflections_tree[kind] value = kind_subtree[token].to_s if value[0..0] != InflectorCfg::Markers::ALIAS if kind_subtree.has_key?(token) return token else raise I18n::BadInflectionToken.new(locale, token, kind) end else orig_token = token token = value[1..-1] if InflectorCfg::Reserved::Tokens.invalid?(token, :DB) raise I18n::BadInflectionToken.new(locale, token, kind) end token = token.to_sym if kind_subtree[token].nil? raise BadInflectionAlias.new(locale, orig_token, kind, token) else shorten_inflection_alias(token, kind, locale, inflections_tree, count) end end end |