Method: I18n::Inflector::InflectionData#add_alias

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

#add_alias(name, target) ⇒ Boolean #add_alias(name, target, kind) ⇒ Boolean

Adds an alias (overwriting an existing alias).

Overloads:

  • #add_alias(name, target) ⇒ Boolean

    Adds an alias (overwriting an existing alias).

    Parameters:

    • name (Symbol)

      the name of an alias

    • target (Symbol)

      the target token for the given alias

    Returns:

    • (Boolean)

      true if everything went ok, false otherwise (in case of bad or nil names or non-existent targets)

  • #add_alias(name, target, kind) ⇒ Boolean

    Adds an alias (overwriting an existing alias) if the given kind matches the kind of the given target.

    Parameters:

    • name (Symbol)

      the name of an alias

    • target (Symbol)

      the target token for the given alias

    • kind (Symbol)

      the optional kind of a taget

    Returns:

    • (Boolean)

      true if everything went ok, false otherwise (in case of bad or nil names or non-existent targets)

Returns:

  • (Boolean)

    true if everything went ok, false otherwise (in case of bad or nil names or non-existent targets)

[View source]

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/i18n-inflector/inflection_data.rb', line 48

def add_alias(name, target, kind=nil)
  target  = target.to_s
  name    = name.to_s
  return false if (name.empty? || target.empty?)
  kind    = nil if kind.to_s.empty? unless kind.nil?
  name    = name.to_sym
  target  = target.to_sym
  t_kind  = get_kind(target)
  return false if (t_kind.nil? || (!kind.nil? && t_kind != kind))
  @tokens[name] = {}
  @tokens[name][:kind]        = kind
  @tokens[name][:target]      = target
  @tokens[name][:description] = @tokens[target][:description]
  true
end