Skip to content

Show topic counts for custom nav links matching /new and /unread and Add per-language translation support for custom nav links - #58

Merged
Grubba27 merged 4 commits into
discourse:mainfrom
akanora:main
Jul 23, 2026
Merged

Show topic counts for custom nav links matching /new and /unread and Add per-language translation support for custom nav links#58
Grubba27 merged 4 commits into
discourse:mainfrom
akanora:main

Conversation

@akanora

@akanora akanora commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Custom nav links pointing to /new or /unread now display the topic count in parentheses (e.g., "New (24)"), matching the behavior of Discourse's built-in navigation items. The count is retrieved from the TopicTrackingState service and updates reactively. Links with other URLs remain unchanged.

Admins can now provide locale-specific overrides for display_name and title on each nav link, while locales without an override automatically fall back to the default value.

Custom nav links pointing to /new or /unread now display the topic
count in parentheses (e.g., "New (24)"), matching the behavior of
Discourse's built-in navigation items. The count is retrieved from
the TopicTrackingState service and updates reactively. Links with
other URLs remain unchanged.
@akanora
akanora force-pushed the main branch 2 times, most recently from 697d81a to 22a1303 Compare July 18, 2026 11:46
@akanora akanora changed the title Show topic counts for custom nav links matching /new and /unread Show topic counts for custom nav links matching /new and /unread and Add per-language translation support for custom nav links Jul 18, 2026
@Grubba27

Copy link
Copy Markdown

This looks good. Do you mind adding some tests?

@pmusaraj pmusaraj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, linting should be addressed.

Comment thread locales/en.yml
url:
label: URL
description: The link (e.g., /latest or https://discourse.org)
translations:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you look into https://meta.discourse.org/t/add-localizable-strings-to-themes-and-theme-components/109867 for the translations? Is it possible to expose the field values so that they can be translated using the theme translations provided by default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked into the theme translations approach (locales/*.yml + i18n(themePrefix(...))). Unfortunately, I think it's not feasible for this use case. Theme translations require pre-defined keys at development time, but nav link display names and titles are dynamic values configured by the admin through type: objects settings. When an admin adds a new link (e.g. "FAQ"), there's no corresponding translation key in the locale files, and admins can't create new keys through the Theme Translations UI they can only edit existing ones.

Instead, I've added a nested translations objects property inside each nav link, where admins can add per-locale overrides with a locale dropdown (type: enum with all Discourse-supported locales) and translated display_name/title fields. At runtime, I18n.currentLocale() is matched against these entries (exact match first, then prefix fallback), falling back to the base values for any unconfigured language.

"/unread": "unread",
};

function getCountForFilter(topicTrackingState, filterType) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Topic counts look reasonable. Would be good to add a test for these as @Grubba27 noted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify what kind of tests you'd like?

@pmusaraj pmusaraj Jul 20, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A qunit or system test that uses the theme component, and validates that the New / Unread count is shown in the item.

@pmusaraj pmusaraj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks! @Grubba27 WDYT?

@akanora
akanora force-pushed the main branch 2 times, most recently from 5bfb680 to 7898653 Compare July 21, 2026 13:58

@Grubba27 Grubba27 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good I would just remove the console log from the test file(line 62)

@pmusaraj

Copy link
Copy Markdown
Contributor

@akanora you need to keep the test you had before f329676 and remove the console.logs.

@akanora

akanora commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@akanora you need to keep the test you had before f329676 and remove the console.logs.

I'm testing something

@akanora

akanora commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@akanora you need to keep the test you had before f329676 and remove the console.logs.

Okey I reverted to b0c0e5d

@Grubba27

Copy link
Copy Markdown

tests failed @akanora. Maybe something is missing in the setup of the test

@akanora

akanora commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

tests failed @akanora. Maybe something is missing in the setup of the test

will try few things

@akanora
akanora force-pushed the main branch 4 times, most recently from 8ff6f33 to c310f81 Compare July 21, 2026 15:31
@akanora

akanora commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

tests failed @akanora. Maybe something is missing in the setup of the test

sorry for taking long on this. i've never dealt with tests before and I was so complicated. the final version should be good. could you please check? @Grubba27

Comment on lines +8 to +9
let originalNavLinks;
let originalShowCounts;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to have these variables? If you remove them, would it work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're there to reset settings back to its original state after the test runs, since settings is a shared object that isn't automatically reset between tests. Without the afterEach restore, my mutations to nav_links and Show_counts would leak into other tests that run later, potentially causing unrelated failures that are hard to trace back. The test itself would still pass without them, but it's insurance against test pollution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the honest answer is: it depends on how settings is initialized/reset in this specific test environment, and I haven't confirmed that.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is fine. All good

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there anything else I can do?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all is good, you may merge it!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do the merging? Do I even have permission for that?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, I think not. It is fine, I'll merge it. Thanks a lot for the contribution!

@Grubba27
Grubba27 merged commit 74fb0b3 into discourse:main Jul 23, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants