Method: I18n::Inflector::InflectionOptions#unknown_defaults

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

#unknown_defaultsBoolean

Note:

Local option :inflector_unknown_defaults passed to the Backend::Inflector#translate overrides this setting.

When this switch is set to true then inflector falls back to the default token for a kind if an inflection option passed to the Backend::Inflector#translate is unknown or nil. Note that the value of the default token will be interpolated only when this token is present in a pattern. This switch is by default set to true.

Examples:

YAML:

en:
 i18n:
   inflections:
     gender:
       n:       'neuter'
       o:       'other'
       default:  n

 welcome:         "Dear @{n:You|o:Other}"
 welcome_free:    "Dear @{n:You|o:Other|Free}"

Example 1


# :gender option is not present,
# unknown tokens in options are falling back to default

I18n.t('welcome')
# => "Dear You"

# :gender option is not present,
# unknown tokens from options are not falling back to default

I18n.t('welcome', :inflector_unknown_defaults => false)
# => "Dear You"

# other way of setting an option – globally

I18n.inflector.options.unknown_defaults = false
I18n.t('welcome')
# => "Dear You"

# :gender option is not present, free text is present,
# unknown tokens from options are not falling back to default

I18n.t('welcome_free', :inflector_unknown_defaults => false)
# => "Dear You"

Example 2


# :gender option is nil,
# unknown tokens from options are falling back to default token for a kind

I18n.t('welcome', :gender => nil)
# => "Dear You"

# :gender option is nil
# unknown tokens from options are not falling back to default token for a kind

I18n.t('welcome', :gender => nil, :inflector_unknown_defaults => false)
# => "Dear "

# :gender option is nil, free text is present
# unknown tokens from options are not falling back to default token for a kind

I18n.t('welcome_free', :gender => nil, :inflector_unknown_defaults => false)
# => "Dear Free"

Example 3


# :gender option is unknown,
# unknown tokens from options are falling back to default token for a kind

I18n.t('welcome', :gender => :unknown_blabla)
# => "Dear You"

# :gender option is unknown,
# unknown tokens from options are not falling back to default token for a kind

I18n.t('welcome', :gender => :unknown_blabla, :inflector_unknown_defaults => false)
# => "Dear "

# :gender option is unknown, free text is present
# unknown tokens from options are not falling back to default token for a kind

I18n.t('welcome_free', :gender => :unknown_blabla, :inflector_unknown_defaults => false)
# => "Dear Free"

Parameters:

  • state (Boolean)

    true enables, false disables this switch

Returns:

  • (Boolean)

    state of the switch


236
237
238
# File 'lib/i18n-inflector/options.rb', line 236

def unknown_defaults
  @unknown_defaults
end