Module: Pagy::I18n
Overview
Pagy i18n implementation, compatible with the I18n gem, just a lot faster and lighter
Defined Under Namespace
Modules: P11n
Constant Summary collapse
- DATA =
Stores the i18n DATA structure for each loaded locale default on the first locale DATA
Hash.new { |hash, _| hash.first[1] }
Instance Method Summary collapse
-
#load(*locales) ⇒ Object
Public method to configure the locales: overrides the default, build the DATA and freezes it.
-
#translate(locale, key, opts = {}) ⇒ Object
(also: #t)
Translate and pluralize the key with the locale DATA.
Instance Method Details
#load(*locales) ⇒ Object
Public method to configure the locales: overrides the default, build the DATA and freezes it
149 150 151 152 153 |
# File 'lib/pagy/i18n.rb', line 149 def load(*locales) DATA.clear build(*locales) DATA.freeze end |
#translate(locale, key, opts = {}) ⇒ Object Also known as: t
Translate and pluralize the key with the locale DATA
156 157 158 159 160 161 |
# File 'lib/pagy/i18n.rb', line 156 def translate(locale, key, opts = {}) data, pluralize = DATA[locale] translation = data[key] || (opts[:count] && data[key += ".#{pluralize.call(opts[:count])}"]) \ or return %([translation missing: "#{key}"]) translation.gsub(/%{[^}]+?}/) { |match| opts[:"#{match[2..-2]}"] || match } end |