Sha256: 0ef35c56acb4411bcf74abcc7f19ac38673a0281d48e696d3b8fd86715b0c58b

Contents?: true

Size: 820 Bytes

Versions: 2

Compression:

Stored size: 820 Bytes

Contents

# See https://ddnexus.github.io/pagy/api/frontend#i18n
# encoding: utf-8
# frozen_string_literal: true

# this file returns the I18n hash used as default alternative to the i18n gem

Hash.new{|h,_| h.first[1]}.tap do |i18n_hash|   # first loaded locale used as default
  i18n_hash.define_singleton_method(:load) do |*load_args|
    # eval: we don't need to keep the loader proc in memory
    eval(Pagy.root.join('locales', 'utils', 'loader.rb').read).call(i18n_hash, *load_args)   #rubocop:disable Security/Eval
  end
  i18n_hash.define_singleton_method(:t) do |locale, key, **opts|
    data, pluralize = self[locale]
    translate = data[key] || opts[:count] && data[key+=".#{pluralize.call(opts[:count])}"] or return %([translation missing: "#{key}"])
    translate.call(opts)
  end
  i18n_hash.load(locale: 'en')
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pagy-4.1.0 lib/locales/utils/i18n.rb
pagy-4.0.0 lib/locales/utils/i18n.rb