lib/locales/utils/i18n.rb in pagy-3.7.3 vs lib/locales/utils/i18n.rb in pagy-3.7.4

- old
+ new

@@ -2,17 +2,24 @@ # 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| # first loaded locale used as default - i18n.define_singleton_method(:load) do |*args| +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, *args) #rubocop:disable Security/Eval + eval(Pagy.root.join('locales', 'utils', 'loader.rb').read).call(i18n_hash, *load_args) #rubocop:disable Security/Eval end - i18n.define_singleton_method(:t) do |locale, path, vars={}| + 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 data, pluralize = self[locale] translate = data[path] || vars[:count] && data[path+=".#{pluralize.call(vars[:count])}"] or return %([translation missing: "#{path}"]) translate.call(vars) end - i18n.load(locale: 'en') + i18n_hash.load(locale: 'en') end