Module: LocalizedFrontend::InflectorExtension::InflectorInstanceMethods
- Defined in:
- lib/localized_frontend/inflector_extension.rb
Overview
The in_localized_scope method is the only thing you need here. Everything else is obscure and retarded.
The methods plural
, singular
and uncountable
is a simple re-definition of the original method in Inflector. The change is simple - use methods instead of instance variables. So, when the plural
method used to do @plurals.insert, we change it so that it does plurals.insert. Then, these methods (singulars
, plurals
and uncountables
) are returning the inflections we want in the language we request. If Inflector.inflections.localize
is set to true, we’ll get un-overrided methods was originally using).
irregulars
are not re-defined, as that method is calling the plural
and singular
methods anyway. Which we have already overrided.
Instance Method Summary collapse
- #current_scope(type) ⇒ Object
-
#in_localized_scope(&block) ⇒ Object
Sets the scope as localized.
- #plural(rule, replacement) ⇒ Object
- #plurals ⇒ Object
- #singular(rule, replacement) ⇒ Object
- #singulars ⇒ Object
- #uncountable(*words) ⇒ Object
- #uncountables ⇒ Object
Instance Method Details
#current_scope(type) ⇒ Object
89 90 91 92 |
# File 'lib/localized_frontend/inflector_extension.rb', line 89 def current_scope(type) prefix = localize ? "localized_" : nil instance_variable_get("@#{prefix}#{type}") end |
#in_localized_scope(&block) ⇒ Object
Sets the scope as localized. This is what String#local_pluralize and friends does.
"car".pluralize # => "cars"
"car".localized_pluralize # => "carer"
Inflector.inflections.in_localized_scope { "car".pluralize } # => "carer"
81 82 83 84 85 86 87 |
# File 'lib/localized_frontend/inflector_extension.rb', line 81 def in_localized_scope(&block) self.localize = true result = yield self.localize = false result end |
#plural(rule, replacement) ⇒ Object
106 107 108 |
# File 'lib/localized_frontend/inflector_extension.rb', line 106 def plural(rule, replacement) plurals.insert(0, [rule, replacement]) end |
#plurals ⇒ Object
98 99 100 |
# File 'lib/localized_frontend/inflector_extension.rb', line 98 def plurals current_scope(:plurals) end |
#singular(rule, replacement) ⇒ Object
110 111 112 |
# File 'lib/localized_frontend/inflector_extension.rb', line 110 def singular(rule, replacement) singulars.insert(0, [rule, replacement]) end |
#singulars ⇒ Object
94 95 96 |
# File 'lib/localized_frontend/inflector_extension.rb', line 94 def singulars current_scope(:singulars) end |
#uncountable(*words) ⇒ Object
114 115 116 |
# File 'lib/localized_frontend/inflector_extension.rb', line 114 def uncountable(*words) (uncountables << words).flatten! end |
#uncountables ⇒ Object
102 103 104 |
# File 'lib/localized_frontend/inflector_extension.rb', line 102 def uncountables current_scope(:uncountables) end |