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

Open
akanora wants to merge 3 commits into
discourse:mainfrom
akanora:main
Open

Show topic counts for custom nav links matching /new and /unread and Add per-language translation support for custom nav links#58
akanora wants to merge 3 commits into
discourse:mainfrom
akanora:main

Conversation

@akanora

@akanora akanora commented Jul 18, 2026

Copy link
Copy Markdown

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
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
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.

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