A platform for community discussion. Free, open, simple.
FIX: Take into account language fallbacks for admin sidebar plugin links (#27061)
Martin Brennanf2cdc3b2a41a
diff --git a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.jsindex 408fdfbd127..b1c840fa6f2 100644--- a/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js+++ b/app/assets/javascripts/discourse/app/lib/sidebar/admin-sidebar.js@@ -210,7 +210,10 @@ export function addAdminSidebarSectionLink(sectionName, link) {}// label must be valid, don't want broken [XYZ translation missing]- if (link.label && typeof I18n.lookup(link.label) !== "string") {+ if (+ link.label &&+ I18n.t(link.label) === I18n.missingTranslation(link.label, null, {})+ ) {// eslint-disable-next-line no-consoleconsole.debug("[AdminSidebar]",diff --git a/app/assets/javascripts/discourse/tests/acceptance/admin-sidebar-section-test.js b/app/assets/javascripts/discourse/tests/acceptance/admin-sidebar-section-test.jsindex 03a4776fa86..c561b9651f8 100644--- a/app/assets/javascripts/discourse/tests/acceptance/admin-sidebar-section-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/admin-sidebar-section-test.js@@ -8,6 +8,7 @@ import {count,exists,} from "discourse/tests/helpers/qunit-helpers";+import I18n from "discourse-i18n";acceptance("Admin Sidebar - Sections", function (needs) {needs.user({@@ -210,3 +211,44 @@ acceptance("Admin Sidebar - Sections - Plugin API", function (needs) {);});});++let _locale;+acceptance(+ "Admin Sidebar - Sections - Plugin API - Translation Fallbacks",+ function (needs) {+ needs.user({+ admin: true,+ groups: [AUTO_GROUPS.admins],+ use_admin_sidebar: true,+ });++ needs.hooks.beforeEach(() => {+ _locale = I18n.locale;+ I18n.locale = "fr_FOO";++ withPluginApi("1.24.0", (api) => {+ api.addAdminSidebarSectionLink("root", {+ name: "test_section_link",+ label: "admin.plugins.title",+ route: "adminPlugins.index",+ icon: "cog",+ });+ });+ });++ needs.hooks.afterEach(() => {+ I18n.locale = _locale;+ });++ test("valid links that are yet to be translated can be added to a section with the plugin API because of I18n fallback", async function (assert) {+ await visit("/admin");++ assert.ok(+ exists(+ ".sidebar-section[data-section-name='admin-root'] .sidebar-section-link-wrapper[data-list-item-name=\"admin_additional_root_test_section_link\"]"+ ),+ "link is appended to the root section"+ );+ });+ }+);