Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from dhnaranjo/underscore_n
Browse files Browse the repository at this point in the history
Compound word class names properly underscored
  • Loading branch information
joeldrapper authored Dec 8, 2022
2 parents c57fc99 + 5af6cc4 commit b3d852c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/phlex/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ module ClassMethods
attr_writer :translation_path

def translation_path
@translation_path ||= name&.split("::")&.join(".")&.downcase.to_s
end
@translation_path ||= name&.dup.tap do |n|
n.gsub!("::", ".")
n.gsub!(/([a-z])([A-Z])/, '\1_\2')
n.downcase!
end
end

end

def translate(key, **options)
Expand Down
8 changes: 7 additions & 1 deletion test/phlex/translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ def template
it "returns I18n scope using class anme" do
expect(Views::Articles::Form.translation_path).to be == "views.articles.form"
end
end
end

with "a class name with a multiple word class or module name" do
it "converts the names to snake case" do
expect(Views::Articles::OtherForm.translation_path).to be == "views.articles.other_form"
end
end

with "invalid class_name" do
it "returns empty string" do
Expand Down

0 comments on commit b3d852c

Please sign in to comment.