mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 13:12:45 +08:00
FIX: Use fallback locales when searching for translations
This commit is contained in:
parent
cab5dd09d3
commit
2e875d3cca
|
@ -43,7 +43,13 @@ module I18n
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(locale, query)
|
def search(locale, query)
|
||||||
find_results(/#{query}/i, {}, translations[locale])
|
results = {}
|
||||||
|
|
||||||
|
fallbacks(locale).each do |fallback|
|
||||||
|
find_results(/#{query}/i, results, translations[fallback])
|
||||||
|
end
|
||||||
|
|
||||||
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -54,7 +60,9 @@ module I18n
|
||||||
k = k_sym.to_s
|
k = k_sym.to_s
|
||||||
key_path = path ? "#{path}.#{k}" : k
|
key_path = path ? "#{path}.#{k}" : k
|
||||||
if v.is_a?(String)
|
if v.is_a?(String)
|
||||||
results[key_path] = v if key_path =~ regexp || v =~ regexp
|
unless results.has_key?(key_path)
|
||||||
|
results[key_path] = v if key_path =~ regexp || v =~ regexp
|
||||||
|
end
|
||||||
elsif v.is_a?(Hash)
|
elsif v.is_a?(Hash)
|
||||||
find_results(regexp, results, v, key_path)
|
find_results(regexp, results, v, key_path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,6 +40,11 @@ describe I18n::Backend::DiscourseI18n do
|
||||||
expect(results['items.other']).to eq('%{count} items')
|
expect(results['items.other']).to eq('%{count} items')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'uses fallback locales for searching' do
|
||||||
|
expect(backend.search(:de, 'bar')).to eq({'bar' => 'Bar in :de'})
|
||||||
|
expect(backend.search(:de, 'foo')).to eq({'foo' => 'Foo in :en'})
|
||||||
|
end
|
||||||
|
|
||||||
describe '#exists?' do
|
describe '#exists?' do
|
||||||
it 'returns true when a key is given that exists' do
|
it 'returns true when a key is given that exists' do
|
||||||
expect(backend.exists?(:de, :bar)).to eq(true)
|
expect(backend.exists?(:de, :bar)).to eq(true)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user