FIX: Locale mismatch at theme translations picker (#26687)

* FIX: Locale mismatch at theme translations picker

Before, the theme translations picker value was set to the
site's default locale, which mismatches from the user's locale.

This commit changes the picker value to the user locale.

relates to https://meta.discourse.org/t/locale-mismatch-at-theme-translations/302879

* DEV: Address code review feedback.

- https://github.com/discourse/discourse/pull/26687#discussion_r1572516758
- https://github.com/discourse/discourse/pull/26687#discussion_r1572524059
This commit is contained in:
Gabriel Grubba 2024-04-19 19:23:27 +02:00 committed by GitHub
parent 239eac7799
commit dc996a1e5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 2 deletions

View File

@ -302,7 +302,11 @@ export default class AdminCustomizeThemesShowController extends Controller {
}
get locale() {
return this.get("model.locale") || this.siteSettings.default_locale;
return (
this.get("model.locale") ||
this.userLocale ||
this.siteSettings.default_locale
);
}
@action

View File

@ -41,6 +41,7 @@ export default class AdminCustomizeThemesShowRoute extends Route {
colorSchemes: parentController.get("model.extras.color_schemes"),
editingName: false,
editingThemeSetting: false,
userLocale: parentController.get("model.extras.locale"),
});
this.handleHighlight(model);

View File

@ -176,6 +176,7 @@ class Admin::ThemesController < Admin::AdminController
themes: serialize_data(@themes, ThemeSerializer),
extras: {
color_schemes: serialize_data(@color_schemes, ColorSchemeSerializer),
locale: current_user.effective_locale,
},
}

View File

@ -3,7 +3,7 @@
describe "Admin Customize Themes", type: :system do
fab!(:color_scheme)
fab!(:theme)
fab!(:admin)
fab!(:admin) { Fabricate(:admin, locale: "en") }
let(:admin_customize_themes_page) { PageObjects::Pages::AdminCustomizeThemes.new }
@ -160,5 +160,33 @@ describe "Admin Customize Themes", type: :system do
theme_translations_settings_editor.fill_in("Hello World in French")
theme_translations_settings_editor.save
end
it "should match the current user locale translation" do
SiteSetting.allow_user_locale = true
SiteSetting.set_locale_from_accept_language_header = true
SiteSetting.default_locale = "fr"
theme.set_field(
target: :translations,
name: "en",
value: { en: { group: { hello: "Hello there!" } } }.deep_stringify_keys.to_yaml,
)
theme.set_field(
target: :translations,
name: "fr",
value: { fr: { group: { hello: "Bonjour!" } } }.deep_stringify_keys.to_yaml,
)
theme.save!
visit("/admin/customize/themes/#{theme.id}")
theme_translations_settings_editor =
PageObjects::Components::AdminThemeTranslationsSettingsEditor.new
expect(theme_translations_settings_editor.get_input_value).to have_content("Hello there!")
theme_translations_picker = PageObjects::Components::SelectKit.new(".translation-selector")
expect(theme_translations_picker.component.text).to eq("English (US)")
end
end
end