lib/locales/utils/i18n.rb in pagy-3.14.0 vs lib/locales/utils/i18n.rb in pagy-4.0.0
- old
+ new
@@ -2,24 +2,17 @@
# encoding: utf-8
# frozen_string_literal: true
# this file returns the I18n hash used as default alternative to the i18n gem
-Pagy::DEPRECATED_LOCALES = {'pt-br' =>'pt-BR', 'se' => 'sv-SE'}
-
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, path, vars={}|
- if Pagy::DEPRECATED_LOCALES.key?(locale)
- new_locale = Pagy::DEPRECATED_LOCALES[locale]
- $stderr.puts("WARNING: the Pagy locale '#{locale}' is deprecated; use '#{new_locale}' instead")
- locale = new_locale
- end
+ i18n_hash.define_singleton_method(:t) do |locale, key, **opts|
data, pluralize = self[locale]
- translate = data[path] || vars[:count] && data[path+=".#{pluralize.call(vars[:count])}"] or return %([translation missing: "#{path}"])
- translate.call(vars)
+ 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