Skip to content

Commit

Permalink
Merge branch 'main' into fix/explicit_authorization
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Nov 21, 2024
2 parents c156c06 + c3134f5 commit 6e71a61
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ GIT
PATH
remote: .
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.1_ruby_3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
PATH
remote: ..
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_6.1_ruby_3.3.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
PATH
remote: ..
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.1_ruby_3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
PATH
remote: ..
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.1_ruby_3.3.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
PATH
remote: ..
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.2.0.beta2_ruby_3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
PATH
remote: ..
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_7.2.0.beta2_ruby_3.3.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PATH
PATH
remote: ..
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8.0_ruby_3.1.4.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ PATH
PATH
remote: ..
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails_8.0_ruby_3.3.0.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ PATH
PATH
remote: ..
specs:
avo (3.14.1)
avo (3.14.2)
actionview (>= 6.1)
active_link_to
activerecord (>= 6.1)
Expand Down
4 changes: 1 addition & 3 deletions lib/avo/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def translation_key
end

def name
@name ||= name_from_translation_key(count: 1, default: class_name.underscore.humanize)
name_from_translation_key(count: 1, default: class_name.underscore.humanize)
end
alias_method :singular_name, :name

Expand All @@ -203,8 +203,6 @@ def name_from_translation_key(count:, default:)
end

def underscore_name
return @name if @name.present?

name.demodulize.underscore
end

Expand Down
2 changes: 1 addition & 1 deletion lib/avo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Avo
VERSION = "3.14.1" unless const_defined?(:VERSION)
VERSION = "3.14.2" unless const_defined?(:VERSION)
end
5 changes: 5 additions & 0 deletions spec/dummy/config/locales/avo.pt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
pt:
avo:
resource_translations:
product: "Produto"
22 changes: 16 additions & 6 deletions spec/features/avo/generators/locales_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@

RSpec.feature "locales generator", type: :feature do
it "generates the files" do
# Backup the en locale
en_locale_backup = Rails.root.join("config", "locales", "avo.en.yml.bak")
FileUtils.cp(Rails.root.join("config", "locales", "avo.en.yml"), en_locale_backup)
# Define locales to backup
backup_locales = %w[en pt]

locales = %w[en fr nn nb pt-BR pt ro tr ar ja es]
# Backup locales
backup_files = {}
backup_locales.each do |locale|
original_file = Rails.root.join("config", "locales", "avo.#{locale}.yml")
backup_file = Rails.root.join("config", "locales", "avo.#{locale}.yml.bak")
FileUtils.cp(original_file, backup_file) if File.exist?(original_file)
backup_files[locale] = {original: original_file, backup: backup_file}
end

locales = %w[ar de en es fr it ja nb nl nn pl pt-BR pt ro ru tr uk zh]

files = locales.map do |locale|
Rails.root.join("config", "locales", "avo.#{locale}.yml").to_s
Expand All @@ -21,7 +29,9 @@

check_files_and_clean_up files

# Restore the en locale
FileUtils.mv(en_locale_backup, Rails.root.join("config", "locales", "avo.en.yml"))
# Restore locales from backup
backup_files.each do |locale, paths|
FileUtils.mv(paths[:backup], paths[:original]) if File.exist?(paths[:backup])
end
end
end
11 changes: 11 additions & 0 deletions spec/features/avo/localization_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require "rails_helper"

RSpec.feature "Localization spec", type: :feature do
describe "force_locale" do
it "translates the resource name on the create button" do
visit avo.resources_products_path(force_locale: :pt)

expect(page).to have_text "Criar novo produto"
end
end
end

0 comments on commit 6e71a61

Please sign in to comment.