Class: GlobalizeTranslation
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GlobalizeTranslation
- Defined in:
- app/models/globalize_translation.rb
Class Method Summary collapse
- .available_locales ⇒ Object
-
.is_interpolation_mandatory?(language_code, key) ⇒ Boolean
based on doc/pluralization_analysis which was written while analysing unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html.
- .lookup(keys) ⇒ Object
Instance Method Summary collapse
Class Method Details
.available_locales ⇒ Object
15 16 17 |
# File 'app/models/globalize_translation.rb', line 15 def self.available_locales find(:all, :select => 'DISTINCT locale').map { |t| t.locale.to_sym } end |
.is_interpolation_mandatory?(language_code, key) ⇒ Boolean
based on doc/pluralization_analysis which was written while analysing
http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html
key - one of ‘zero’, ‘one’, ‘two’, ‘few’, ‘many’, ‘other’
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/globalize_translation.rb', line 27 def self.is_interpolation_mandatory?(language_code, key) rule = I18n.t(:'i18n.plural.rule', :locale => language_code.to_sym, :resolve => false) key = key.to_sym case key when :zero return false when :one return rule.call(0) == :one || rule.call(21) == :one when :two return rule.call(102) == :two when :few return rule.call(4) == :few when :many return rule.call(6) != :many || rule.call(11) == :many when :other return true else raise "unexpected key: #{key}" end end |
.lookup(keys) ⇒ Object
8 9 10 11 12 13 |
# File 'app/models/globalize_translation.rb', line 8 def self.lookup(keys) column_name = connection.quote_column_name('key') keys = Array(keys).map! { |key| key.to_s } namespace = "#{keys.last}#{I18n::Backend::Flatten::FLATTEN_SEPARATOR}%" scoped(:conditions => ["#{column_name} IN (?) OR #{column_name} LIKE ?", keys, namespace]) end |
Instance Method Details
#last_key ⇒ Object
19 20 21 |
# File 'app/models/globalize_translation.rb', line 19 def last_key key.split(".").last end |