diff --git a/lib/gettext_i18n_rails/backend.rb b/lib/gettext_i18n_rails/backend.rb index 38f8b8d..601f2ac 100644 --- a/lib/gettext_i18n_rails/backend.rb +++ b/lib/gettext_i18n_rails/backend.rb @@ -23,7 +23,12 @@ def translate(locale, key, options) interpolate(translation, options) else result = backend.translate(locale, key, options) - (RUBY19 and result.is_a?(String)) ? result.force_encoding("UTF-8") : result + if RUBY19 && result.is_a?(String) + result = result.dup if result.frozen? + result.force_encoding("UTF-8") + else + result + end end end end diff --git a/spec/gettext_i18n_rails/backend_spec.rb b/spec/gettext_i18n_rails/backend_spec.rb index 5cb0bd1..857e2aa 100644 --- a/spec/gettext_i18n_rails/backend_spec.rb +++ b/spec/gettext_i18n_rails/backend_spec.rb @@ -79,6 +79,13 @@ subject.translate('xx', 'c', {}).should == 'd' end + it "passes non-gettext keys to default backend without modifying frozen translation" do + subject.backend.should_receive(:translate).with('xx', 'c', {}).and_return 'd'.freeze + # TODO track down why this is called 3 times on 1.8 (only 1 time on 1.9) + FastGettext.stub(:current_repository).and_return 'a'=>'b' + subject.translate('xx', 'c', {}).should == 'd' + end + it 'temporarily sets the given locale' do FastGettext.should_receive(:set_locale).with('xx').and_return('xy') FastGettext.should_receive(:set_locale).with('xy').and_return('xx')