diff --git a/app/models/translation.rb b/app/models/translation.rb index 56a5af2c57c7..d78f120260f7 100644 --- a/app/models/translation.rb +++ b/app/models/translation.rb @@ -74,7 +74,7 @@ def self.lang(locale) =end def self.translate(locale, string, *args) - translated = find_source(locale, string)&.target || string + translated = find_source(locale, string)&.target.presence || string translated %= args if args.any? diff --git a/spec/models/translation_spec.rb b/spec/models/translation_spec.rb index d59a732097ca..3b28acd5a018 100644 --- a/spec/models/translation_spec.rb +++ b/spec/models/translation_spec.rb @@ -36,6 +36,17 @@ end end + context 'default string translations with fallback' do + before do + create(:translation, locale: 'de-de', source: 'dummy message', target: '', target_initial: '') + described_class.sync_locale_from_po('de-de') + end + + it 'fallbacks to provided message/string when de-de is empty' do + expect(described_class.translate('de-de', 'dummy message')).to eq('dummy message') + end + end + context 'when using find_source' do it 'de-de with existing title case word' do expect(described_class.find_source('de-de', 'New')).to have_attributes(source: 'New', target_initial: 'Neu', target: 'Neu')