Skip to content

Commit

Permalink
removed deprecated locales
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Mar 8, 2021
1 parent a70881a commit f075337
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 29 deletions.
7 changes: 0 additions & 7 deletions lib/locales/utils/i18n.rb
Expand Up @@ -4,19 +4,12 @@

# 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
data, pluralize = self[locale]
translate = data[path] || vars[:count] && data[path+=".#{pluralize.call(vars[:count])}"] or return %([translation missing: "#{path}"])
translate.call(vars)
Expand Down
5 changes: 0 additions & 5 deletions lib/locales/utils/loader.rb
Expand Up @@ -20,11 +20,6 @@
lambda do |i18n, *args|
i18n.clear
args.each do |arg|
if Pagy::DEPRECATED_LOCALES.key?(arg[:locale])
new_locale = Pagy::DEPRECATED_LOCALES[arg[:locale]]
$stderr.puts("WARNING: the Pagy locale '#{arg[:locale]}' is deprecated; use '#{new_locale}' instead")
arg[:locale] = new_locale
end
arg[:filepath] ||= Pagy.root.join('locales', "#{arg[:locale]}.yml")
arg[:pluralize] ||= plurals[arg[:locale]]
hash = YAML.load(File.read(arg[:filepath], encoding: 'UTF-8')) #rubocop:disable Security/YAMLLoad
Expand Down
17 changes: 0 additions & 17 deletions test/pagy/frontend_test.rb
Expand Up @@ -106,23 +106,6 @@

end

describe "Pagy::I18n deprecation" do

it 'handles deprecated locales' do
_(proc {Pagy::I18n.load({locale: 'se'}, {locale: 'pt-br'})}).must_output '', /^WARNING:/

view.instance_variable_set(:'@pagy_locale', 'se')
_(proc {view.pagy_t('pagy.item_name', count: 1).must_equal 'resultat'}).must_output '', /^WARNING:/

view.instance_variable_set(:'@pagy_locale', 'pt-br')
_(proc {view.pagy_t('pagy.item_name', count: 1).must_equal 'item'}).must_output '', /^WARNING:/

Pagy::I18n.load(locale: 'en') # reset for other tests
view.instance_variable_set(:'@pagy_locale', nil) # reset for other tests
end

end

describe "#pagy_info" do

it 'renders without i18n path' do
Expand Down

0 comments on commit f075337

Please sign in to comment.