Class: I18n::Inflector::API

Inherits:
API_Strict show all
Includes:
Interpolate
Defined in:
lib/i18n-inflector/api.rb,
lib/i18n-inflector/long_comments.rb

Overview

Instance of this class, the inflector, is attached to I18n backend. This class contains common operations that can be performed on inflections. It can operate on both unnamed an named patterns (regular and strict kinds). This class is used by backend methods to interpolate strings and load inflections.

It uses the databases containing instances of InflectionData and InflectionData_Strict that are stored in the Hashes and indexed by locale names.

Note that strict kinds used to handle named patterns internally are stored in a different database than regular kinds. Most of the methods of this class are also aware of strict kinds and will call proper methods handling strict inflection data when the @ symbol is detected at the beginning of the given identifier of a kind.

Usage

You can access the instance of this class attached to default I18n backend by calling:

I18n.backend.inflector

or in a short form:

I18n.inflector

In case of named patterns (strict kinds):

I18n.inflector.strict

Direct Known Subclasses

Core

Constant Summary

Constants included from Config

Config::MULTI_REGEXP, Config::MULTI_RESTR, Config::OPTION_PREFIX, Config::OPTION_PREFIX_REGEXP, Config::PATTERN_REGEXP, Config::PATTERN_RESTR, Config::TOKENS_REGEXP, Config::TOKENS_RESTR

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Interpolate

#interpolate, #key_to_pattern

Methods inherited from API_Strict

#aliases, #delete_database, #each_kind, #prep_locale, #tokens, #tokens_raw, #tokens_true

Constructor Details

#initializeAPI

Initilizes the inflector by creating internal databases used for storing inflection data and options.



83
84
85
86
# File 'lib/i18n-inflector/api.rb', line 83

def initialize
  super(nil, nil)
  @idb_strict = {}
end

Instance Attribute Details

#configObject (readonly)

This reader allows to reach internal configuration of the engine. It is shared among all instances of the Inflector and also available as I18n::Inflector::Config.



70
71
72
# File 'lib/i18n-inflector/api.rb', line 70

def config
  I18n::Inflector::Config
end

#optionsI18n::Inflector::InflectionOptions (readonly)

Options controlling the engine.

Examples:

Usage of options:

# globally set raises flag
I18n.inflector.options.raises = true

# globally set raises flag (the same meaning as the example above)
I18n.backend.inflector.options.raises = true

# set raises flag just for this translation
I18n.translate('welcome', :inflector_raises => true)

Returns:

See Also:



67
68
69
# File 'lib/i18n-inflector/api.rb', line 67

def options
  @options
end

#strictI18n::Inflector::API_Strict (readonly)

This reader allows to reach a reference of the object that is a kind of I18n::Inflector::API_Strict and handles inflections for named patterns (strict kinds).

Returns:



75
76
77
# File 'lib/i18n-inflector/api.rb', line 75

def strict
  @strict ||= I18n::Inflector::API_Strict.new(@idb_strict, @options)
end

Instance Method Details

#add_database(db) ⇒ I18n::Inflector::InflectionData? #add_database(db, db_strict) ⇒ Array<I18n::Inflector::InflectionData,I18n::Inflector::InflectionData_Strict>? Also known as: add_databases

Note:

It doesn’t create a copy of inflection data, but registers the given object(s).

Attaches instance of InflectionData and optionally InflectionData_Strict to the inflector.

Overloads:

Returns:

Raises:



134
135
136
137
138
139
140
141
142
143
# File 'lib/i18n-inflector/api.rb', line 134

def add_database(db, db_strict=nil)
  r = super(db)
  return r if (r.nil? || db_strict.nil?)
  r_strict = strict.add_database(db_strict)
  if r_strict.nil?
    delete_database(db.locale)
    return nil
  end
  [r, r_strict]
end

#default_token(kind) ⇒ Symbol? #default_token(kind, locale) ⇒ Symbol?

Note:

If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#default_token)

Reads default token for the given kind.

Overloads:

  • #default_token(kind) ⇒ Symbol?

    This method reads default token for the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of tokens

    Returns:

    • (Symbol, nil)

      the default token or nil if there is no default token

  • #default_token(kind, locale) ⇒ Symbol?

    This method reads default token for the given kind and the given locale.

    Parameters:

    • kind (Symbol, String)

      the kind of tokens

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol, nil)

      the default token or nil if there is no default token

Returns:

  • (Symbol, nil)

    the default token or nil

Raises:



267
268
269
270
271
272
273
# File 'lib/i18n-inflector/api.rb', line 267

def default_token(kind, locale=nil)
  return nil if (kind.nil? || kind.to_s.empty?)
  if kind.to_s[0..0] == Markers::STRICT_KIND
    return strict.default_token(kind.to_s[1..-1], locale)
  end
  super
end

#delete_databases(locale)

Note:

It detaches the databases from I18n::Inflector::API instance. Other objects referring to them may still use it.

This method returns an undefined value.

Deletes the internal databases for the specified locale.

Parameters:

  • locale (Symbol)

    the locale for which the inflections database is to be deleted.

Raises:



154
155
156
157
# File 'lib/i18n-inflector/api.rb', line 154

def delete_databases(locale)
  delete_database(locale)
  strict.delete_database(locale)
end

#each_alias(kind) ⇒ LazyHashEnumerator #each_alias(kind, locale) ⇒ LazyHashEnumerator

Iterates through inflection aliases and their pointers.

Overloads:

  • #each_alias(kind) ⇒ LazyHashEnumerator
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#each_alias)

    Iterates through inflection aliases (and their pointers) of the given kind and the current locale.

    Parameters:

    • kind (Symbol, String)

      the kind of aliases to get

    Returns:

  • #each_alias(kind, locale) ⇒ LazyHashEnumerator
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#each_alias)

    Iterates through inflection aliases (and their pointers) of the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of aliases to get

    • locale (Symbol)

      the locale to use

    Returns:

Yields:

  • (alias, target)

    optional block in which each alias will be yielded

Yield Parameters:

  • alias (Symbol)

    an alias

  • target (Symbol)

    a name of the target token

Yield Returns:

Returns:

Raises:



635
636
637
638
639
640
# File 'lib/i18n-inflector/api.rb', line 635

def each_alias(kind=nil, locale=nil, &block)
  if kind.to_s[0..0] == Markers::STRICT_KIND
    return strict.each_alias(kind.to_s[1..-1], locale, &block)
  end
  super
end

#each_inflected_localeLazyArrayEnumerator #each_inflected_locale(kind) ⇒ LazyArrayEnumerator Also known as: each_locale, each_supported_locale

Note:

This method uses information from both regular and strict kinds. The locale identifiers may be duplicated!

Iterates through locales which have configured inflection support.

Overloads:

  • #each_inflected_localeLazyArrayEnumerator

    Iterates through locales which have configured inflection support.

    Returns:

  • #each_inflected_locale(kind) ⇒ LazyArrayEnumerator

    Iterates through locales which have configured inflection support for the given kind.

    Parameters:

    • kind (Symbol)

      the identifier of a kind

    Returns:

Yields:

  • (locale)

    optional block in which each kind will be yielded

Yield Parameters:

  • locale (Symbol)

    the inflected locale identifier

Yield Returns:

Returns:



219
220
221
# File 'lib/i18n-inflector/api.rb', line 219

def each_inflected_locale(kind=nil, &block)
  super + strict.inflected_locales(kind)
end

#each_tokenLazyHashEnumerator #each_token(kind) ⇒ LazyHashEnumerator #each_token(kind, locale) ⇒ LazyHashEnumerator

Note:

By default it uses regular kinds database, not strict kinds.

Note:

You cannot deduce where aliases are pointing to, since the information about a target is replaced by the description. To get targets use the I18n::Inflector::API_Strict#raw_tokens method. To simply list aliases and their targets use the I18n::Inflector::API_Strict#aliases method.

Iterates through available inflection tokens and their descriptions.

Overloads:

  • #each_tokenLazyHashEnumerator

    Iterates through available inflection tokens and their descriptions.

    Returns:

  • #each_token(kind) ⇒ LazyHashEnumerator
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#each_token)

    Iterates through available inflection tokens and their descriptions for some kind.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

  • #each_token(kind, locale) ⇒ LazyHashEnumerator
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#each_token)

    Iterates through available inflection tokens and their descriptions for some kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

Yields:

  • (token, description)

    optional block in which each token will be yielded

Yield Parameters:

  • token (Symbol)

    a token

  • description (String)

    a description string for a token

Yield Returns:

Returns:

Raises:



537
538
539
540
541
542
# File 'lib/i18n-inflector/api.rb', line 537

def each_token(kind=nil, locale=nil)
  if kind.to_s[0..0] == Markers::STRICT_KIND
    return strict.each_token(kind.to_s[1..-1], locale)
  end
  super
end

#each_token_rawLazyHashEnumerator #each_token_raw(kind) ⇒ LazyHashEnumerator #each_token_raw(kind, locale) ⇒ LazyHashEnumerator Also known as: each_raw_token

Note:

You may deduce whether the returned values are aliases or true tokens by testing if a value is a type of Symbol or String.

Iterates through available inflection tokens and their values.

Overloads:

  • #each_token_rawLazyHashEnumerator

    Iterates through available inflection tokens and their values for regular kinds.

    Returns:

  • #each_token_raw(kind) ⇒ LazyHashEnumerator
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#each_token_raw)

    Iterates through available inflection tokens and their values for the given kind.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

  • #each_token_raw(kind, locale) ⇒ LazyHashEnumerator
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#each_token_raw)

    Iterates through available inflection tokens and their values for the given kind and locale.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

Yields:

  • (token, value)

    optional block in which each token will be yielded

Yield Parameters:

  • token (Symbol)

    a token

  • value (Symbol, String)

    a description string for a token or a target (if alias)

Yield Returns:

Returns:

Raises:



571
572
573
574
575
576
# File 'lib/i18n-inflector/api.rb', line 571

def each_token_raw(kind=nil, locale=nil)
  if kind.to_s[0..0] == Markers::STRICT_KIND
    return strict.each_token_raw(kind.to_s[1..-1], locale)
  end
  super
end

#each_token_trueLazyHashEnumerator #each_token_true(kind) ⇒ LazyHashEnumerator #each_token_true(kind, locale) ⇒ LazyHashEnumerator Also known as: each_true_token

Note:

It returns only true tokens, not aliases.

Iterates through true inflection tokens and their values.

Overloads:

  • #each_token_trueLazyHashEnumerator

    Iterates through true inflection tokens and their values for regular kinds.

    Returns:

  • #each_token_true(kind) ⇒ LazyHashEnumerator
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#each_token_true)

    Iterates through true inflection tokens and their values for the given kind.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    Returns:

  • #each_token_true(kind, locale) ⇒ LazyHashEnumerator
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#each_token_true)

    Iterates through true inflection tokens and their values for the given kind and value.

    Parameters:

    • kind (Symbol, String)

      the kind of inflection tokens to be returned

    • locale (Symbol)

      the locale to use

    Returns:

Yields:

  • (token, description)

    optional block in which each token will be yielded

Yield Parameters:

  • token (Symbol)

    a token

  • description (String)

    a description string for a token

Yield Returns:

Returns:

Raises:



605
606
607
608
609
610
# File 'lib/i18n-inflector/api.rb', line 605

def each_token_true(kind=nil, locale=nil, &block)
  if kind.to_s[0..0] == Markers::STRICT_KIND
    return strict.each_token_true(kind.to_s[1..-1], locale, &block)
  end
  super
end

#has_alias?(token) ⇒ Boolean #has_alias?(token, locale) ⇒ Boolean #has_alias?(token, kind, locale) ⇒ Boolean #has_alias?(token, strict_kind) ⇒ Boolean Also known as: token_has_alias?

Note:

By default it uses regular kinds database, not strict kinds.

Checks if the given token is an alias.

Overloads:

  • #has_alias?(token) ⇒ Boolean

    Uses current locale to check if the given token is an alias.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    Returns:

    • (Boolean)

      true if the given token is an alias, false otherwise

  • #has_alias?(token, locale) ⇒ Boolean

    Uses the given locale to check if the given token is an alias.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token is an alias, false otherwise

  • #has_alias?(token, kind, locale) ⇒ Boolean
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#has_alias?)

    Uses the given locale and kind to check if the given token is an alias.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind used to narrow the check

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token is an alias, false otherwise

  • #has_alias?(token, strict_kind) ⇒ Boolean
    Note:

    It calls I18n::Inflector::API_Strict#has_alias? on strict kinds data.

    Uses the current locale and the given strict_kind (which name must begin with the @ symbol) to check if the given token is an alias.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • strict_kind (Symbol, String)

      the kind of the given alias

    Returns:

    • (Boolean)

      true if the given token is an alias, false otherwise

Returns:

  • (Boolean)

    true if the given token is an alias, false otherwise

Raises:



306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/i18n-inflector/api.rb', line 306

def has_alias?(*args)
  token, kind, locale = tkl_args(args)
  return false if (token.nil? || token.to_s.empty?)
  unless kind.nil?
    kind = kind.to_s
    reutrn false if kind.empty?
    if kind[0..0] == Markers::STRICT_KIND
      return strict.has_alias?(token, kind[1..-1], locale)
    end
    kind = kind.to_sym
  end
  data_safe(locale).has_alias?(token.to_sym, kind)
end

#has_kind?(kind) ⇒ Boolean #has_kind?(kind, locale) ⇒ Boolean

Note:

If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#has_kind?)

Tests if a kind exists.

Overloads:

  • #has_kind?(kind) ⇒ Boolean

    Tests if a regular kind exists for the current locale.

    Parameters:

    • kind (Symbol)

      the identifier of a kind

    Returns:

    • (Boolean)

      true if the given kind exists for the current locale, false otherwise

  • #has_kind?(kind, locale) ⇒ Boolean

    Tests if a regular kind exists for the given locale.

    Parameters:

    • kind (Symbol, String)

      the identifier of a kind

    • locale (Symbol)

      the locale identifier

    Returns:

    • (Boolean)

      true if the given kind exists, false otherwise

Returns:

  • (Boolean)

    true if the given kind exists, false otherwise

Raises:



242
243
244
245
246
247
# File 'lib/i18n-inflector/api.rb', line 242

def has_kind?(kind, locale=nil)
  if kind.to_s[0..0] == Markers::STRICT_KIND
    return strict.has_kind?(kind.to_s[1..-1], locale)
  end
  super
end

#has_token?(token) ⇒ Boolean #has_token?(token, locale) ⇒ Boolean #has_token?(token, kind, locale) ⇒ Boolean #has_token?(token, strict_kind) ⇒ Boolean Also known as: token_exists?

Note:

By default it uses regular kinds database, not strict kinds.

Checks if the given token exists. It may be an alias or a true token.

Overloads:

  • #has_token?(token) ⇒ Boolean

    Uses current locale to check if the given token is a token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    Returns:

    • (Boolean)

      true if the given token exists, false otherwise

  • #has_token?(token, locale) ⇒ Boolean

    Uses the given locale to check if the given token exists.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token exists, false otherwise

  • #has_token?(token, kind, locale) ⇒ Boolean
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#has_token?)

    Uses the given locale and kind to check if the given token exists.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind used to narrow the check

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token exists, false otherwise

  • #has_token?(token, strict_kind) ⇒ Boolean
    Note:

    It calls I18n::Inflector::API_Strict#has_token? on strict kinds data.

    Uses the current locale and the given strict_kind (which name must begin with the @ symbol) to check if the given token exists.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • strict_kind (Symbol, String)

      the kind of the given token

    Returns:

    • (Boolean)

      true if the given token exists, false otherwise

Returns:

  • (Boolean)

    true if the given token exists, false otherwise

Raises:



398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/i18n-inflector/api.rb', line 398

def has_token?(*args)
  token, kind, locale = tkl_args(args)
  return false if (token.nil? || token.to_s.empty?)
  unless kind.nil?
    kind = kind.to_s
    return false if kind.empty?
    if kind[0..0] == Markers::STRICT_KIND
      return strict.has_token?(token, kind[1..-1], locale)
    end
    kind = kind.to_sym
  end
  data_safe(locale).has_token?(token.to_sym, kind)
end

#has_true_token?(token) ⇒ Boolean #has_true_token?(token, locale) ⇒ Boolean #has_true_token?(token, kind, locale) ⇒ Boolean #has_true_token?(token, strict_kind) ⇒ Boolean Also known as: token_has_true?

Note:

By default it uses regular kinds database, not strict kinds.

Checks if the given token is a true token (not alias).

Overloads:

  • #has_true_token?(token) ⇒ Boolean

    Uses current locale to check if the given token is a true token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    Returns:

    • (Boolean)

      true if the given token is a true token, false otherwise

  • #has_true_token?(token, locale) ⇒ Boolean

    Uses the given locale to check if the given token is a true token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token is a true token, false otherwise

  • #has_true_token?(token, kind, locale) ⇒ Boolean
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#has_true_token?)

    Uses the given locale and kind to check if the given token is a true token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind used to narrow the check

    • locale (Symbol)

      the locale to use

    Returns:

    • (Boolean)

      true if the given token is a true token, false otherwise

  • #has_true_token?(token, strict_kind) ⇒ Boolean
    Note:

    It calls I18n::Inflector::API_Strict#has_true_token? on strict kinds data.

    Uses the current locale and the given strict_kind (which name must begin with the @ symbol) to check if the given token is a true token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • strict_kind (Symbol, String)

      the kind of the given token

    Returns:

    • (Boolean)

      true if the given token is a true token, false otherwise

Returns:

  • (Boolean)

    true if the given token is a true token, false otherwise

Raises:



352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/i18n-inflector/api.rb', line 352

def has_true_token?(*args)
  token, kind, locale = tkl_args(args)
  return false if (token.nil? || token.to_s.empty?)
  unless kind.nil?
    kind = kind.to_s
    return false if kind.empty?
    if kind[0..0] == Markers::STRICT_KIND
      return strict.has_true_token?(token, kind[1..-1], locale)
    end
    kind = kind.to_sym
  end
  data_safe(locale).has_true_token?(token.to_sym, kind)
end

#inflected_locale?(locale) ⇒ Boolean #inflected_locale?Boolean Also known as: locale?, locale_supported?

Note:

That method uses information from regular and strict kinds.

Checks if the given locale was configured to support inflection.

Overloads:

  • #inflected_locale?(locale) ⇒ Boolean

    Checks if the given locale was configured to support inflection.

    Parameters:

    • locale (Symbol)

      the locale to test

    Returns:

    • (Boolean)

      true if the given locale supports inflection

  • #inflected_locale?Boolean

    Checks if the current locale was configured to support inflection.

    Returns:

    • (Boolean)

      true if the current locale supports inflection

Returns:

  • (Boolean)

    true if a locale supports inflection

Raises:



172
173
174
# File 'lib/i18n-inflector/api.rb', line 172

def inflected_locale?(locale=nil)
  super || strict.inflected_locale?(locale)
end

#inflected_localesArray<Symbol> #inflected_locales(kind) ⇒ Array<Symbol>

Note:

This method uses information from both regular and strict kinds.

Gets locales which have configured inflection support.

Overloads:

  • #inflected_localesArray<Symbol>

    Gets locales which have configured inflection support.

    Returns:

    • (Array<Symbol>)

      the array containing locales that support inflection

  • #inflected_locales(kind) ⇒ Array<Symbol>
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#inflected_locales)

    Gets locales which have configured inflection support for the given kind.

    Parameters:

    • kind (Symbol)

      the identifier of a kind

    Returns:

    • (Array<Symbol>)

      the array containing locales that support inflection

Returns:

  • (Array<Symbol>)

    the array containing locales that support inflection



193
194
195
196
197
198
199
200
201
# File 'lib/i18n-inflector/api.rb', line 193

def inflected_locales(kind=nil)
  if kind.to_s[0..0] == Markers::STRICT_KIND
    strict.inflected_locales(kind.to_s[1..-1])
  else
    kind = kind.to_s.empty? ? nil : kind.to_sym
    r = ( @inflected_locales_cache[kind] ||= super(kind).uniq )
    r.nil? ? r : r.dup
  end
end

#kind(token) ⇒ Symbol? #kind(token, locale) ⇒ Symbol? #kind(token, kind, locale) ⇒ Symbol? #kind(token, strict_kind) ⇒ Symbol?

Note:

By default it uses regular kinds database, not strict kinds.

Gets a kind for the given token (which may be an alias).

Overloads:

  • #kind(token) ⇒ Symbol?

    Uses the current locale to get a kind of the given token (which may be an alias).

    Parameters:

    • token (Symbol, String)

      name of the token or alias

    Returns:

    • (Symbol, nil)

      the kind of the given token

  • #kind(token, locale) ⇒ Symbol?

    Uses the given locale to get a kind of the given token (which may be an alias).

    Parameters:

    • token (Symbol, String)

      name of the token or alias

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol, nil)

      the kind of the given token

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

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#kind)

    Uses the given locale to get a kind of the given token (which may be an alias).

    Parameters:

    • token (Symbol, String)

      name of the token or alias

    • kind (Symbol, String)

      the kind name to narrow the search

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol, nil)

      the kind of the given token

  • #kind(token, strict_kind) ⇒ Symbol?
    Note:

    It calls I18n::Inflector::API_Strict#kind on strict kinds data.

    Uses the current locale and the given strict_kind (which name must begin with the @ symbol) to get a kind of the given token (which may be an alias).

    Parameters:

    • token (Symbol, String)

      name of the token or alias

    • kind (Symbol, String)

      the kind of the given token

    Returns:

    • (Symbol, nil)

      the kind of the given token

Returns:

  • (Symbol, nil)

    the kind of the given token or nil

Raises:



493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/i18n-inflector/api.rb', line 493

def kind(*args)
  token, kind, locale = tkl_args(args)
  return nil if (token.nil? || token.to_s.empty?)
  unless kind.nil?
    kind = kind.to_s
    return nil if kind.empty?
    if kind[0..0] == Markers::STRICT_KIND
      return strict.kind(token, kind[1..-1], locale)
    end
    kind = kind.to_sym
  end
  data_safe(locale).get_kind(token.to_sym, kind)
end

#kindsArray<Symbol> #kinds(locale) ⇒ Array<Symbol> Also known as: inflection_kinds

Note:

To get all inflection kinds (regular and strict) for default inflector use: I18n.inflector.kinds + I18n.inflector.strict.kinds

Gets known regular inflection kinds.

Overloads:

  • #kindsArray<Symbol>

    Gets known inflection kinds for the current locale.

    Returns:

    • (Array<Symbol>)

      the array containing known inflection kinds

  • #kinds(locale) ⇒ Array<Symbol>

    Gets known inflection kinds for the given locale.

    Parameters:

    • locale (Symbol)

      the locale for which operation has to be done

    Returns:

    • (Array<Symbol>)

      the array containing known inflection kinds

Returns:

  • (Array<Symbol>)

    the array containing known inflection kinds

Raises:



46
# File 'lib/i18n-inflector/long_comments.rb', line 46

def kinds(locale=nil); super end

#new_database(locale) ⇒ I18n::Inflector::InflectionData

Creates a database for the specified locale.

Parameters:

  • locale (Symbol)

    the locale for which the inflections database is to be created

Returns:

Raises:



94
95
96
97
# File 'lib/i18n-inflector/api.rb', line 94

def new_database(locale)
  locale = prep_locale(locale)
  @idb[locale] = I18n::Inflector::InflectionData.new(locale)
end

#new_databases(locale) ⇒ Array<I18n::Inflector::InflectionData,I18n::Inflector::InflectionData_Strict>

Creates internal databases (regular and strict) for the specified locale.

Parameters:

  • locale (Symbol)

    the locale for which the inflections databases are to be created

Returns:

Raises:



106
107
108
109
110
# File 'lib/i18n-inflector/api.rb', line 106

def new_databases(locale)
  normal = new_databases(locale)
  strict = strict.new_database(locale)
  [normal, strict]
end

#tkl_args(token, kind, locale) ⇒ Array<Symbol,Symbol,Symbol> (protected) #tkl_args(token, locale) ⇒ Array<Symbol,Symbol,Symbol> (protected) #tkl_args(token) ⇒ Array<Symbol,Symbol,Symbol> (protected) #tkl_args(token, strict_kind) ⇒ Array<Symbol,Symbol,Symbol> (protected)

Note:

This method leaves kind as is when it’s nil or empty. It sets token to nil when it’s empty.

This method is the internal helper that prepares arguments containing token, kind and locale.

Overloads:

  • #tkl_args(token, kind, locale) ⇒ Array<Symbol,Symbol,Symbol>

    Prepares arguments containing token, kind and locale.

    Parameters:

    • token (String, Hash)

      the token

    • kind (String, Hash)

      the inflection kind

    • locale (String, Hash)

      the locale identifier

    Returns:

    • (Array<Symbol,Symbol,Symbol>)

      the array containing cleaned and validated token, kind and locale

  • #tkl_args(token, locale) ⇒ Array<Symbol,Symbol,Symbol>

    Prepares arguments containing token and locale.

    Parameters:

    • token (String, Hash)

      the token

    • locale (String, Hash)

      the locale identifier

    Returns:

    • (Array<Symbol,Symbol,Symbol>)

      the array containing cleaned and validated token, kind and locale

  • #tkl_args(token) ⇒ Array<Symbol,Symbol,Symbol>

    Prepares arguments containing token.

    Parameters:

    • token (String, Hash)

      the token

    Returns:

    • (Array<Symbol,Symbol,Symbol>)

      the array containing cleaned and validated token and the current locale

  • #tkl_args(token, strict_kind) ⇒ Array<Symbol,Symbol,Symbol>

    Prepares arguments containing token and strict_kind.

    Parameters:

    • token (String, Hash)

      the token

    • strict_kind (String, Hash)

      the strict kind identifier beginning with @ symbol

    Returns:

    • (Array<Symbol,Symbol,Symbol>)

      the array containing cleaned and validated token, strict_kind and the current locale

Returns:

  • (Array<Symbol,Symbol,Symbol>)

    the array containing cleaned and validated token, kind and locale

Raises:



739
740
741
742
743
744
745
746
747
# File 'lib/i18n-inflector/api.rb', line 739

def tkl_args(args)
  token, kind, locale = case args.count
  when 1 then [args[0], nil, nil]
  when 2 then args[1].to_s[0..0] == Markers::STRICT_KIND ? [args[0], args[1], nil] : [args[0], nil, args[1]]
  when 3 then args
  else raise I18n::ArgumentError.new("wrong number of arguments: #{args.count} for (1..3)")
  end
  [token,kind,locale]
end

#token_description(token) ⇒ String? #token_description(token, locale) ⇒ String? #token_description(token, kind, locale) ⇒ String? #token_description(token, strict_kind) ⇒ String?

Note:

If the given token is really an alias it returns the description of the true token that it points to. By default it uses regular kinds database, not strict kinds.

Gets the description of the given inflection token.

Overloads:

  • #token_description(token) ⇒ String?

    Uses current locale to get description of the given inflection token.

    Parameters:

    • token (Symbol)

      the identifier of a token

    Returns:

    • (String, nil)

      the descriptive string or nil if something went wrong (e.g. token was not found)

  • #token_description(token, locale) ⇒ String?

    Uses the given locale to get description of the given inflection token.

    Parameters:

    • token (Symbol, String)

      the identifier of a token

    • locale (Symbol)

      the locale to use

    Returns:

    • (String, nil)

      the descriptive string or nil if something went wrong (e.g. token was not found)

  • #token_description(token, kind, locale) ⇒ String?
    Note:

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#token_description)

    Uses the given locale and kind to get description of the given inflection token.

    Parameters:

    • token (Symbol, String)

      the identifier of a token

    • kind (Symbol, String)

      the kind to narrow the results

    • locale (Symbol)

      the locale to use

    Returns:

    • (String, nil)

      the descriptive string or nil if something went wrong (e.g. token was not found or kind mismatched)

  • #token_description(token, strict_kind) ⇒ String?
    Note:

    It calls I18n::Inflector::API_Strict#token_description on strict kinds data.

    Uses the default locale and the given kind (which name must begin with the @ symbol) to get description of the given inflection token.

    Parameters:

    • token (Symbol, String)

      the identifier of a token

    • strict_kind (Symbol, String)

      the kind of a token

    • locale (Symbol)

      the locale to use

    Returns:

    • (String, nil)

      the descriptive string or nil if something went wrong (e.g. token was not found or kind mismatched)

Returns:

  • (String, nil)

    the descriptive string or nil

Raises:



680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/i18n-inflector/api.rb', line 680

def token_description(*args)
  token, kind, locale = tkl_args(args)
  return nil if (token.nil? || token.to_s.empty?)
  unless kind.nil?
    kind = kind.to_s
    return nil if kind.empty?
    if kind[0..0] == Markers::STRICT_KIND
      return strict.token_description(token, kind[1..-1], locale)
    end
    kind = kind.to_sym
  end
  data_safe(locale).get_description(token.to_sym, kind)
end

#true_token(token) ⇒ Symbol? #true_token(token, locale) ⇒ Symbol? #true_token(token, kind, locale) ⇒ Symbol? #true_token(token, strict_kind) ⇒ Symbol? Also known as: resolve_alias

Note:

By default it uses regular kinds database, not strict kinds.

Gets true token for the given token. If the token is an alias it will be resolved and a true token (target) will be returned.

Overloads:

  • #true_token(token) ⇒ Symbol?

    Uses current locale to get a real token for the given token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    Returns:

    • (Symbol, nil)

      the true token or nil

  • #true_token(token, locale) ⇒ Symbol?

    Uses the given locale to get a real token for the given token. If the token is an alias it will be resolved and a true token (target) will be returned.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol, nil)

      the true token or nil

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

    If kind begins with the @ symbol then the variant of this method operating on strict kinds will be called (I18n::Inflector::API_Strict#true_token)

    Uses the given locale and kind to get a real token for the given token. If the token is an alias it will be resolved and a true token (target) will be returned.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • kind (Symbol, String)

      the kind of the given token

    • locale (Symbol)

      the locale to use

    Returns:

    • (Symbol, nil)

      the true token or nil

  • #true_token(token, strict_kind) ⇒ Symbol?
    Note:

    It calls I18n::Inflector::API_Strict#true_token on strict kinds data.

    Uses the current locale and the given strict_kind (which name must begin with the @ symbol) to get a real token for the given token.

    Parameters:

    • token (Symbol, String)

      name of the checked token

    • strict_kind (Symbol, String)

      the kind of the given token

    Returns:

    • (Symbol, nil)

      the true token

Returns:

  • (Symbol, nil)

    the true token or nil

Raises:



448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/i18n-inflector/api.rb', line 448

def true_token(*args)
  token, kind, locale = tkl_args(args)
  return nil if (token.nil? || token.to_s.empty?)
  unless kind.nil?
    kind = kind.to_s
    return nil if kind.empty?
    if kind[0..0] == Markers::STRICT_KIND
      return strict.true_token(token, kind[1..-1], locale)
    end
    kind = kind.to_sym
  end
  data_safe(locale).get_true_token(token.to_sym, kind)
end