mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Incorrect locale in badge granter (#8749)
We want to use default locale when: a) Site settings are not allowing for user locale OR b) User locale are blank
This commit is contained in:
committed by
GitHub
parent
0420be88a6
commit
aa04349cfd
@@ -380,11 +380,13 @@ class BadgeGranter
|
|||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.send_notification(user_id, username, locale, badge)
|
def self.notification_locale(locale)
|
||||||
use_default_locale = !SiteSetting.allow_user_locale && locale.blank?
|
use_default_locale = !SiteSetting.allow_user_locale || locale.blank?
|
||||||
notification_locale = use_default_locale ? SiteSetting.default_locale : locale
|
use_default_locale ? SiteSetting.default_locale : locale
|
||||||
|
end
|
||||||
|
|
||||||
I18n.with_locale(notification_locale) do
|
def self.send_notification(user_id, username, locale, badge)
|
||||||
|
I18n.with_locale(notification_locale(locale)) do
|
||||||
Notification.create!(
|
Notification.create!(
|
||||||
user_id: user_id,
|
user_id: user_id,
|
||||||
notification_type: Notification.types[:granted_badge],
|
notification_type: Notification.types[:granted_badge],
|
||||||
|
|||||||
@@ -322,4 +322,20 @@ describe BadgeGranter do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'notification locales' do
|
||||||
|
it 'is using default locales when user locales are not set' do
|
||||||
|
SiteSetting.allow_user_locale = true
|
||||||
|
expect(BadgeGranter.notification_locale('')).to eq(SiteSetting.default_locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is using default locales when user locales are set but is not allowed' do
|
||||||
|
SiteSetting.allow_user_locale = false
|
||||||
|
expect(BadgeGranter.notification_locale('pl_PL')).to eq(SiteSetting.default_locale)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'is using user locales when set and allowed' do
|
||||||
|
SiteSetting.allow_user_locale = true
|
||||||
|
expect(BadgeGranter.notification_locale('pl_PL')).to eq('pl_PL')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user