Method: I18n::Backend::Inflector#shorten_inflection_alias

Defined in:
lib/i18n-inflector/backend.rb

#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.

Overloads:

  • #shorten_inflection_alias(token, kind, locale) ⇒ Symbol
    Note:

    This version uses internal subtree and needs the translation data to be initialized.

    Resolves an alias for a token if the given token is an alias for the given locale and kind.

    Parameters:

    • token (Symbol)

      the token name

    • kind (Symbol)

      the kind of the given token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol)

      the true token that alias points to if the given token is an alias or the given token if it is a true token

  • #shorten_inflection_alias(token, kind, locale, subtree) ⇒ Symbol

    Resolves an alias for a token if the given token is an alias for the given locale and kind.

    Parameters:

    • token (Symbol)

      the token name

    • kind (Symbol)

      the kind of the given token

    • locale (Symbol)

      the locale to use

    • subtree (Hash)

      the tree (in a form of nested Hashes) containing inflection tokens to scan

    Returns:

    • (Symbol)

      the true token that alias points to if the given token is an alias or the given token if it is a true token

Returns:

  • (Symbol)

    the true token that alias points to if the given token is an alias or the given token if it is a true token

Raises:

[View source]

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