Show topic counts for custom nav links matching /new and /unread and Add per-language translation support for custom nav links#58
Conversation
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.
697d81a to
22a1303
Compare
|
This looks good. Do you mind adding some tests? |
pmusaraj
left a comment
There was a problem hiding this comment.
Also, linting should be addressed.
| url: | ||
| label: URL | ||
| description: The link (e.g., /latest or https://discourse.org) | ||
| translations: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Topic counts look reasonable. Would be good to add a test for these as @Grubba27 noted.
There was a problem hiding this comment.
Could you clarify what kind of tests you'd like?
There was a problem hiding this comment.
A qunit or system test that uses the theme component, and validates that the New / Unread count is shown in the item.
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.