Skip to content

Commit

Permalink
formatting + docs
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Jan 6, 2025
1 parent c2bba50 commit 1d42da2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
25 changes: 13 additions & 12 deletions lib/fast_gettext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,20 @@ def self.add_text_domain(name, options)
translation_repositories[name] = TranslationRepository.build(name, options)
end

# deprecated, just a crutch to migrate to new api
def self.allow_invalid_keys!
eval(<<CODE)
class ::String
alias :_fast_gettext_old_format_m :%
def %(*args)
begin
_fast_gettext_old_format_m(*args)
rescue KeyError
self
end
end
end
CODE
eval(<<~CODE)
class ::String
alias :_fast_gettext_old_format_m :%
def %(*args)
begin
_fast_gettext_old_format_m(*args)
rescue KeyError
self
end
end
end
CODE
end

# some repositories know where to store their locales
Expand Down
13 changes: 6 additions & 7 deletions spec/fast_gettext/vendor/string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,11 @@ def %(*args)
it "does not raise when key was not found if allow_invalid_keys! is enabled" do
FastGettext.allow_invalid_keys!
("%{typo} xxx" % {:something=>1}).should == "%{typo} xxx"

# cleanup
eval(<<CODE)
class ::String
alias :% :_fast_gettext_old_format_m
end
CODE
ensure # cleanup
eval <<~CODE
class ::String
alias :% :_fast_gettext_old_format_m
end
CODE
end
end

0 comments on commit 1d42da2

Please sign in to comment.