diff --git a/lib/fast_gettext.rb b/lib/fast_gettext.rb index 86de8a89..d794ec04 100644 --- a/lib/fast_gettext.rb +++ b/lib/fast_gettext.rb @@ -28,6 +28,21 @@ def self.add_text_domain(name, options) translation_repositories[name] = TranslationRepository.build(name, options) end + def self.allow_invalid_keys! + eval(<'b'}) -rescue KeyError - class String - alias :_fast_gettext_old_format_m :% - def %(*args) - begin - _fast_gettext_old_format_m(*args) - rescue KeyError - self - end - end - end -end diff --git a/spec/fast_gettext/vendor/string_spec.rb b/spec/fast_gettext/vendor/string_spec.rb index 6355e4d4..887ec3d5 100644 --- a/spec/fast_gettext/vendor/string_spec.rb +++ b/spec/fast_gettext/vendor/string_spec.rb @@ -49,7 +49,19 @@ def %(*args) end end - it "does not raise when key was not found" do + it "raise when key was not found" do + lambda { ("%{typo} xxx" % {:something=>1}) }.should raise_error(KeyError) + end + + 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(<